javascript中tips提示特效代碼

來源:互聯網
上載者:User
 代碼如下 複製代碼


Javascript :

// 提示外掛程式
$.tips = function(ele, txt) {

    // 參數
    var r = true, // 外掛程式傳回值
        wrap = $('<div class="tips"><b></b><i></i></div>'), // required包裹元素
        animationTime = 600,
        _this = this, // this
    ;

    // 顯示提示框
    _this.show = function($this) {
        wrap
            .prepend(txt) // 當存在data-required屬性時,提示框顯示其值。
            .css({
                "left" : $this.offset().left + $this.outerWidth() / 2 - 16,
                "top" : $this.offset().top + $this.outerHeight() + 7
            })
        ;
        $("body").append(wrap);

        wrap.fadeIn(animationTime);

        // 移除提示框
        _this.hide($this);
    }

    // 隱藏提示框
    _this.hide = function ($this) {
        var timer = setTimeout(function(){
            _this.remove();
        }, 6000);
        $this.blur(function(){
            clearTimeout(timer);
            _this.remove();
        });
        $this.keydown(function(e) {
            clearTimeout(timer);
            _this.remove();
            $this.unbind("keydown");
        });
    }

    // 移除提示框
    _this.remove = function() {
        wrap.fadeOut(animationTime, function() {
            $(this).remove();
        });
    }

    _this.show(o.ele);
}
CSS :

/* tips提示框 { */
.tips {
    border: 1px solid #C7C7C7;
    background: #fff url(../img/required.gif) no-repeat 6px center;
    padding-right: 16px;
    padding-left: 33px;
    height: 32px;
    font: 14px/32px SimSun, 'Microsoft YaHei', SimHei;
    position: absolute;
    left: 40%;
    top: 300px;
    border-radius: 3px;
    color: #000;
    box-shadow: 0px 2px 5px 0px #c7c7c7;
    display: none;
}
.tips i, .tips b {
    position: absolute;
    width: 0;
    height: 0;
    border-width: 0 7px 7px 7px;
    border-style: solid;
    border-color: transparent transparent #fff transparent;
    top: -7px;
    left: 10px;
}
.tips b {
    top: -8px;
    border-color: transparent transparent #c7c7c7 transparent;
}
/* tips 提示框 } */

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.