tooltip和title美化网站提示教程

tooltip和title美化网站提示教程 第2张插图
浏览器自带的alt和title提示太丑了,所以我们需要美化一下,百度有许多,不过对我们这些小白来说很难。

第一步

放以下js到公用js里面

var sweetTitles = {
    x: 10,
    y: 20,
    tipElements: "a,span,img,div ",
    noTitle: false,
    init: function() {
        var b = this.noTitle;
        $(this.tipElements).each(function() {
            $(this).mouseover(function(e) {
                if (b) {
                    isTitle = true
                } else {
                    isTitle = $.trim(this.title) != ''
                }
                if (isTitle) {
                    this.myTitle = this.title;
                    this.title = "";
                    var a = "<div class='tooltip'><div class='tipsy-arrow tipsy-arrow-n'></div><div class='tipsy-inner'>" + this.myTitle + "</div></div>";
                    $('body').append(a);
                    $('.tooltip').css({
                        "top": (e.pageY + 20) + "px",
                        "left": (e.pageX - 20) + "px"
                    }).show('fast')
                }
            }).mouseout(function() {
                if (this.myTitle != null) {
                    this.title = this.myTitle;
                    $('.tooltip').remove()
                }
            }).mousemove(function(e) {
                $('.tooltip').css({
                    "top": (e.pageY + 20) + "px",
                    "left": (e.pageX - 20) + "px"
                })
            })
        })
    }
};
$(function() {
    sweetTitles.init()
});

第二步css也是放到公用css文件里面

tooltip和title美化网站提示教程 第3张插图
此处内容已隐藏,评论后刷新即可查看!

免责声明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集整理,如果您喜欢该程序和内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如有侵权请邮件与我们联系处理。敬请谅解!
如若转载,请注明出处:https://www.zxki.cn/4037.html

上一篇 2022-6-14 09:12
下一篇 2022-6-14 10:57

相关推荐

发表评论

为了防止灌水评论,登录后即可评论!

已有 25 条评论