国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery插件tooltipv頂部淡入淡出效果使用示例

2019-11-20 21:31:09
字體:
來源:轉載
供稿:網友

 

內部使用


復制代碼 代碼如下:

<head>
    <title></title>
    <link href="base.css" rel="stylesheet" type="text/css" />
    <link href="jquery.tooltip.less" rel="stylesheet/less" type="text/css">

    <script src="less-1.4.2.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
    <script src="jquery.tooltip.js" type="text/javascript"></script>
</head>
<body>
    <div id="tooltipContainer" style="display:none;"></div>
    <button onclick="javascript:tg1();">info</button>
    <button onclick="javascript:tg2();">alert</button>
    <button onclick="javascript:tg3();">hide</button>
    <script language="javascript">
        $("#tooltipContainer").tooltip();  //初始化
        function tg1() {
            $("#tooltipContainer").tooltip("info", "據你的使用和需求的不同...");
        }
        function tg2() {
            $("#tooltipContainer").tooltip("alert", "據你的使用和需求的不同...");
        }
        function tg3() {
            $("#tooltipContainer").tooltip("hide");
        }
    </script>
</body>

css

復制代碼 代碼如下:

.tooltip_info
{
    background:green;
    font-size:20px;
    border-radius: 10px;
}
.tooltip_alert
{
    background:yellow;
    font-size:20px;
    border-radius: 10px;
}

jquery.tooltip插件js代碼

復制代碼 代碼如下:

(function ($) {
    var methods = {
        init: function (options) {
            return this.each(function () {

                var $this = $(this);
                var settings = $this.data('tooltip');
                if (typeof (settings) == 'undefined') {
                    var defaults = {
                        infoCss: 'tooltip_info',
                        alertCss: 'tooltip_alert',
                        disappearTime: 1000
                    }
                    settings = $.extend({}, defaults, options);
                    $this.data('tooltip', settings);
                } else {
                    settings = $.extend({}, settings, options);
                    $this.data('tooltip', settings);
                }
                $tooltip = $("#tooltip");
                $tooltip.hide();
                if ($tooltip.length == 0) {
                    $tooltip = $("<div></div>");
                    $('body').prepend($tooltip);
                    $tooltip.hide();
                }
            })
        },
        info: function (options) {
            return this.each(function () {
                var $this = $(this);
                var setting = $this.data('tooltip');

                clearTimeout($this.data("autoDisappearHandle"));
                $tooltip.html(options);
                $tooltip.removeClass(setting.alertCss).addClass(setting.infoCss);
                $tooltip.fadeIn();
                var hideTooltip = function () {
                    $tooltip.fadeOut();
                }
                $this.data("autoDisappearHandle", setTimeout(hideTooltip, setting.disappearTime));
            })
        },
        alert: function (options) {
            return this.each(function () {
                var $this = $(this);
                var setting = $this.data('tooltip');

                clearTimeout($this.data("autoDisappearHandle"));
                $tooltip.html(options);
                $tooltip.removeClass(setting.infoCss).addClass(setting.alertCss);
                $tooltip.fadeIn();
                var hideTooltip = function () {
                    $tooltip.fadeOut();
                }
                $this.data("autoDisappearHandle", setTimeout(hideTooltip, setting.disappearTime));
            })
        },
        hide: function () {
            return this.each(function () {
                var $this = $(this);
                clearTimeout($this.data("autoDisappearHandle"));
                $tooltip.fadeOut();
            })
        }
    };

    $.fn.tooltip = function () {
        var method = arguments[0];
        if (methods[method]) {
            method = methods[method];
            arguments = Array.prototype.slice.call(arguments, 1);
        } else if (typeof (method) == 'object' || !method) {
            method = methods.init;
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
            return this;
        }

        return method.apply(this, arguments);

    }

})(jQuery);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桓台县| 永胜县| 海原县| 兴国县| 长阳| 那坡县| 新沂市| 汉沽区| 潼南县| 乌鲁木齐县| 沁阳市| 凤冈县| 华宁县| 酒泉市| 彭水| 克山县| 高雄县| 辽宁省| 香格里拉县| 旅游| 米易县| 九江市| 高台县| 昌邑市| 葵青区| 汽车| 东兰县| 陆河县| 治多县| 修文县| 柯坪县| 七台河市| 于田县| 大新县| 云霄县| 石门县| 伊通| 万全县| 娄底市| 泌阳县| 咸宁市|