返回列表 发布新帖
查看: 742|回复: 0

tooltip和title美化网站提示教程

捣蛋鬼魔神·索伦森

梦之瑶-飞哥发表于 2019-11-13 10:11:23 | 查看全部 |阅读模式

您需要登录账号才能看到图片及隐藏内容,马上注册享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

美化演示


教程简介

浏览器自带的alt和title提示太丑了,所以我们需要美化一下,百度有许多,不过对我们这些小白来说很难。
第一步
放以下js到公用js里面

[code=JavaScript]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()
});

[/code]

第二步

css也是

[code=Css]/*tips*/
        .tooltip {
        font-size:12px;
        position:absolute;
        padding:5px;
        z-index:100000;
        opacity:.8;
        font-family:Microsoft Yahei
}
.tipsy-arrow {
        position:absolute;
        width:0;
        height:0;
        line-height:0;
        border:6px dashed #000;
        top:0;
        left:20%;
        margin-left:-5px;
        border-bottom-style:solid;
        border-top:0;
        border-left-color:transparent;
        border-right-color:transparent
}
.tipsy-arrow-n {
        border-bottom-color:#666
}
.tipsy-inner {
        background-color:#666;
        color:#FFF;
        max-width:200px;
        padding:5px 8px 4px 8px;
        text-align:center;
        border-radius:3px
}

[/code]


<
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

投诉/建议联系

xm520vip@gmail.com

未经授权禁止转载,复制和建立镜像,
如有违反,追究法律责任
  • 关注公众号
  • 关注小程序
Copyright © 2001-2025 灵歆论坛 版权所有 All Rights Reserved. |网站地图
关灯 在本版发帖
扫一扫进入小程序页面
QQ客服返回顶部
快速回复 返回顶部 返回列表