【问题标题】:JQUERY ToolTip - Styling Specific WordsJQUERY 工具提示 - 样式化特定单词
【发布时间】:2013-03-24 06:11:34
【问题描述】:

我有这个 jquery:

this.tooltip = function(){  
    /* CONFIG */        
        xOffset = 10;
        yOffset = 20;       
        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result     
    /* END CONFIG */        
    $("a.tooltip").hover(function(e){                                             
        this.t = this.title;
        this.title = "";                                      
        $("body").append("<p id='tooltip'>"+ this.t +"</p>");
        $("#tooltip")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("fast");        
    },
    function(){
        this.title = this.t;        
        $("#tooltip").remove();
    }); 
    $("a.tooltip").mousemove(function(e){
        $("#tooltip")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });         
};



// starting the script on page load
$(document).ready(function(){
    tooltip();
});

与名为“tooltip”的 CSS 类一起使用,其中包含 font-variant:small-caps;

所有工具提示都采用小型大写字母,看起来很棒:)

工具提示是这样调用的: &lt;a href="#" class="tooltip" title="this is the tooltip"&gt;hover to see tooltip&lt;/a&gt;

我想在工具提示中包含一两个单词 BOLD 并且全部小写.. 如何在不破坏工具提示的重置的情况下做到这一点?

所以不要显示为:

这是工具提示

我想要:

这是工具提示

有什么想法吗??

【问题讨论】:

    标签: php jquery css styles


    【解决方案1】:

    您可以为要添加的文本添加特定类,然后通过 CSS 设置样式。 例如

    $("a.tooltip").hover(function(e){                                             
            this.t = this.title;
            this.title = "";                                      
            $("body").append("<p id='tooltip' class='tooltipText'>"+ this.t +"</p>");
            $("#tooltip")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px")
                .fadeIn("fast");        
        },
    

    然后是css:

    .tooltipText
    {
       text-transform: uppercase;
       /* any style you want  */
    
    }
    

    【讨论】:

    • 感谢您的回复.. 但我不确定这是我需要的。与工具提示的其余部分相比,我想将原始工具提示中的几个词改成不同的大小写。我该怎么做?
    • 然后您将需要一个函数来识别您需要更改大小写的单词,具体取决于您希望获得的结果。这种区分的标准是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多