当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 点击HTML页面问号出现提示框

点击HTML页面问号出现提示框

2019年01月23日  | 移动技术网IT编程  | 我要评论
本demo的功能:点击页面按钮在其边缘出现提示信息,点击页面任何一处则消失。 如下图: 1.所需插件: jquery插件; layer插件; 2.HTML内容: ==注意==: 1. class="j help tips"这个class是核心,不可缺少。 2. data tips属性是必须的。 3. ...

本demo的功能:点击页面按钮在其边缘出现提示信息,点击页面任何一处则消失。

如下图:

1.所需插件:

  • jquery插件;
  • layer插件;

2.html内容:

==注意==:

  1. class="j-help-tips"这个class是核心,不可缺少。
  2. data-tips属性是必须的。
  3. data-tips属性中:type:"1"不用修改;
  4. data-tips属性中:txt内容即是要提示的内容。
<html>
    <head>
        <link rel="stylesheet" href="style.css"" type="text/css" />
    </head>
    
    <body>
        <div style="margin-top: 10%; margin-left: 10%;">
            <span class="testspan">
                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容111..."}'>①</i>
            </span>
            
            <span style="margin: 30px;">
                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容222..."}'>②</i>
            </span>
            
            <span style="margin: 30px;">
                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"提示内容333..."}'>③</i>
            </span>
        </div>
    </body>
    
    <!-- jquery -->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <!-- layer -->
    <script src="layer/layer.js" type="text/javascript"></script>
    <!-- 提示插件 -->
    <script src="script.js" type="text/javascript"></script>
    
    <script>
        $(function(){
            <!-- 页面初始化加载 -->
            var tips = new helptips().init();
        })
    </script>
</html>

3.css内容:(非必要)

  • 本demo的css非必须,不影响功能;
.edi-icon {
    font-size: 18px;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -webkit-text-stroke-width: .2px;
    -moz-osx-font-smoothing: grayscale;
    *display: inline;
    *zoom: 1;
    cursor: pointer;
}

4.javascript内容:(核心)

//定义提示弹出框;
var helptipslayer;
//定义弹出框的默认设置;
function helptips(t) {
    this.options = {}, 
    this.options.elem = ".j-help-tips", //与页面class相对应;
    this.options.type = 1, 
    this.options.color = "#8db3d7", 
    this.options.time = 0, //设置0是提示弹出框不会自动消失;可设置为其他数字,以毫秒为单位;
    this.options.titleend = "录入提示", 
    this.options.width = "600px", 
    this.options.height = "", 
    this.options.imgwidth = "233", 
    this.options.imgheight = "375", 
    "undefined" != typeof t && (this.options = $.extend({}, this.options, t)), 
    this.elemobj = $(this.options.elem)
}
!
function() {
    //点击页面任何一处可使提示弹出框消失;
    $(document).on("click", function(event){
        var e = event || window.event;
        var target = e.target || e.srcelement;
        var flag = $(target).hasclass("j-help-tips");
        if(helptipslayer && !flag){
            layer.close(helptipslayer);
        }
    })
}(), helptips.prototype = {
    constructor : helptips,
    init : function() {
        this.bindevent()
    },
    bindevent : function() {
        var t = this;
        t.elemobj.on("click", function() {
            layer.close(helptipslayer);//点击其他任意的提示框按钮,则关闭上一个提示框。
            var i = $(this),
                o = i.data("tips");
            if ("undefined" != typeof o && "undefined" != typeof o.type && 1 == o.type) {
                "undefined" != typeof o && "undefined" != typeof o.txt ? helptipslayer = layer.tips(o.txt, i, {
                    tips : [ t.options.type, t.options.color ],
                    time : t.options.time
                }) : t.log()
            } else {
                if ("undefined" != typeof o.title && "undefined" != typeof o.txt && "undefined" != typeof o.img) {
                    var e = '<div class="m-popup-ct">',
                        n = '<h3 class="tt"><span class="txt_01">' + o.title + t.options.titleend + '</span></h3><div class="line_01"></div>',
                        s = "</div>",
                        l = '<ul class="u-explain-list">',
                        p = o.txt.split("|"),
                        a = p.length;
                    a > 0 && $.each(p, function(t, i) {
                        l += '<li><i class="f-mr5">' + (t + 1) + "</i>" + i + "</li>"
                    });
                    var r = /^[1-9][\d]{0,2}$/,
                        c = t.options.imgwidth,
                        d = t.options.imgheight;
                    "undefined" != typeof o.w && "undefined" != typeof o.h && r.test(o.w) && r.test(o.h) && (c = o.w, d = o.h), l += '<li><i class="f-mr5">' + (a + 1) + "</i><img src=" + o.img + ' width="' + c + '" height="' + d + '"/></li>', l += "</ul>";
                    var h = e + n + l + s;
                    layer.open({
                        title : !1,
                        type : 1,
                        area : [ t.options.width, t.options.height ],
                        shadeclose : !0,
                        maxmin : !1,
                        move : !1,
                        scrollbar : !1,
                        content : h
                    })
                } else {
                    t.log()
                }
            }
        })
    },
    log : function() {
        console.log("请给定提示标题|文字|图片---来自[script.js]函数[helptips]")
    }
};

附上源码下载:

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网