Click the question mark on the HTML page to display the prompt box

Posted by jponte on Wed, 11 Dec 2019 03:11:54 +0100

Function of this demo: click the page button to display a prompt message on its edge, and click anywhere on the page to disappear.

The following picture:

1. Required plug-ins:

  • jquery plug-in;
  • layer plug-in;

2.HTML content:

==Note = =:

  1. class="j-help-tips" this class is the core and indispensable.
  2. The data tips attribute is required.
  3. In the data tips attribute: type: "1" does not need to be modified;
  4. In the data tips attribute: the content of txt is the content to prompt.
<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":"Prompt content 111..."}'>①</i>
            </span>
            
            <span style="margin: 30px;">
                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"Tips 222..."}'>②</i>
            </span>
            
            <span style="margin: 30px;">
                <i class="edi-icon j-help-tips" data-tips='{"type":"1","txt":"Tips 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>
    <!-- Prompt plug-in -->
    <script src="script.js" type="text/javascript"></script>
    
    <script>
        $(function(){
            <!-- Page initialization loading -->
            var tips = new helpTips().init();
        })
    </script>
</html>

3. Content of CSS: (unnecessary)

  • The css of this demo is not necessary and does not affect the function;
.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 content: (core)

//Define prompt pop-up box;
var helpTipsLayer;
//Define the default settings of the pop-up box;
function helpTips(t) {
    this.options = {}, 
    this.options.elem = ".j-help-tips", //Corresponding to page class;
    this.options.type = 1, 
    this.options.color = "#8db3d7", 
    this.options.time = 0, //If set to 0, the prompt pop-up box will not disappear automatically; it can be set to other numbers, in milliseconds;
    this.options.titleEnd = "Entry prompt", 
    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() {
    //Click anywhere on the page to make the prompt pop-up box disappear;
    $(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);//Click any other prompt box button to close the previous prompt box.
            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("Please give the prompt title|Written words|picture---Come from[script.js]function[helpTips]")
    }
};

Download the source code: Source code

Topics: Javascript JQuery Attribute