jQuery tip提示插件(實(shí)例分享)
更新時間:2017年04月28日 09:53:50 作者:longqd
本篇文章主要介紹了jQuery tip提示插件的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧
先聲明,我也是學(xué)了某位大神的...
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>document</title> <style> .tip{ width: 200px; text-align: center; position: relative; border:1px solid #ccc; height: 50px; line-height: 50px; left: 50%; margin-top: 50px; transform: translateX(-50%); } .tip-container{ position: absolute; box-shadow: 2px 2px 5px #f9f9f9; z-index: 999; display: none; } .tip-container .tip-point-top, .tip-container .tip-point-bottom, .tip-container .tip-point-left, .tip-container .tip-point-right{ border:1px solid #dcdcdc; position: relative; background: white; } .tip-content{ padding:5px 10px; background: white; font-size: 12px; line-height: 1.7; font-family: "Helvetica Neue",Helvetica,Arial,"MicroSoft YaHei"; } .tip-container .tip-point-top::after, .tip-container .tip-point-top::before, .tip-container .tip-point-bottom::after, .tip-container .tip-point-bottom::before{ content:""; position: absolute; border:solid transparent; left: 50%; width: 0; height: 0; transform: translate3d(-50%,0,0); -webkit-transform: translate3d(-50%,0,0); } .tip-container .tip-point-right::after, .tip-container .tip-point-right::before, .tip-container .tip-point-left::after, .tip-container .tip-point-left::before{ content:""; position: absolute; border:solid transparent; top: 50%; width: 0; height: 0; transform: translate3d(0,-50%,0); -webkit-transform: translate3d(0,-50%,0); } /*tip-point-top*/ .tip-container .tip-point-top::after{ border-top-color: #fff; top: 100%; border-width: 5px; } .tip-container .tip-point-top::before { border-top-color: #dcdcdc; top: 100%; border-width: 7px; } /*tip-point-bottom*/ .tip-container .tip-point-bottom::after{ border-bottom-color: #fff; bottom: 100%; border-width: 5px; } .tip-container .tip-point-bottom::before { border-bottom-color: #dcdcdc; bottom: 100%; border-width: 7px; } /*tip-point-right*/ .tip-container .tip-point-right::after{ border-right-color: #fff; right: 100%; border-width: 5px; } .tip-container .tip-point-right::before { border-right-color: #dcdcdc; right: 100%; border-width: 7px; } /*tip-point-left*/ .tip-container .tip-point-left::after{ border-left-color: #fff; left: 100%; border-width: 5px; } .tip-container .tip-point-left::before { border-left-color: #dcdcdc; left: 100%; border-width: 7px; } </style> </head> <body> <div class="tip" data-tip="寂寞的天下著憂郁的雨" data-mode="top">天堂不寂寞</div> <div class="tip" data-tip="天堂不寂寞" data-mode="bottom">寂寞的天下著憂郁的雨</div> <div class="tip" data-tip="寂寞的天下著憂郁的雨" data-mode="right">寂寞的天下著憂郁的雨</div> <div class="tip" data-tip="天堂不寂寞" data-mode="left">寂寞的天下著憂郁的雨</div> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script> <script> /** * Created by zxhuan (you@example.com) * Date: 2016/11/28 * Time: 11:14 */ ; (function ($,window,document,undefined) { var modePos; $.fn.tip = function (options) { var set = $.extend({ "mode": "bottom", "speed": 300, "tipText":"提示內(nèi)容" }, options); if(!modePos){ //策略模式 //算法 modePos = { top: function (t, tip) { return { left: t.offset().left + (t.width() - tip.width()) / 2 + "px", top: t.offset().top - tip.height() - 12 + "px" } }, bottom:function(t, tip){ return { left: this.top(t, tip).left, top: t.offset().top + t.height() + 12 + "px" } }, left:function(t, tip){ return{ left:t.offset().left - tip.width()-12+ "px", top:t.offset().top +(t.height()-tip.height())/2+"px" } }, right:function(t, tip){ return{ left:t.offset().left +t.width()+12+ "px", top:t.offset().top +(t.height()-tip.height())/2+"px" } } }; } function Tip(_this){ var _that = $(_this); var _mode = set.mode; var tipText=set.tipText; var _tip=".tip-container"; if (_that.data("mode")) { _mode = _that.data("mode"); } if(_that.data("tip")){ tipText = _that.data("tip"); } _that.css("cursor", "pointer"); _that.hover(function () { var _tipHtml = '<div class="tip-container"><div class="tip-point-' + _mode + '"><div class="tip-content">' + tipText + '</div></div></div>'; _that.removeAttr("title alt"); $("body").append(_tipHtml); $(_tip).css(modePos[_mode](_that,$(_tip))).fadeIn(set.speed); }, function () { $(".tip-container").remove(); }); } return this.each(function () { return new Tip(this); }); } })(jQuery,window,document); $(".tip").tip(); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
jQuery實(shí)現(xiàn)動態(tài)加載(按需加載)javascript文件的方法分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)動態(tài)加載(按需加載)javascript文件的方法,結(jié)合實(shí)例形式分析了jQuery根據(jù)調(diào)用函數(shù)按需動態(tài)加載javascript文件相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-05-05JQuery Dialog(JS 模態(tài)窗口,可拖拽的DIV)
JQuery Dialog(JS模態(tài)窗口,可拖拽的DIV) 效果實(shí)現(xiàn)代碼2010-02-02jQuery中實(shí)現(xiàn)動畫效果的基本操作介紹
本篇文章小編將為大家介紹,在jQuery中實(shí)現(xiàn)動畫效果的基本操作介紹,需要的朋友可以參考一下2013-04-04jQuery插件實(shí)現(xiàn)文件上傳功能(支持拖拽)
這篇文章主要介紹了jQuery插件實(shí)現(xiàn)文件上傳功能,可支持拖拽文件上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-06-06jQuery讀取和設(shè)定KindEditor值的方法
這篇文章主要介紹了jQuery讀取和設(shè)定KindEditor值的方法,大家參考使用吧2013-11-11jQuery實(shí)用小技巧_輸入框文字獲取和失去焦點(diǎn)的簡單實(shí)例
下面小編就為大家?guī)硪黄猨Query實(shí)用小技巧_輸入框文字獲取和失去焦點(diǎn)的簡單實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08jquery submit ie6下失效的原因分析及解決方法
jquery submit ie6下失效的原因分析及解決方法。需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11