layui的tips層的使用方法:首先引入文件layer.css和layer.js文件;然后使用代碼格式為“l(fā)ayer.tips(msg, '#id',{tips: 1},time:10000)”;最后設(shè)置相關(guān)參數(shù)即可。
本教程操作環(huán)境:Windows7系統(tǒng)、layui2.4版,該方法適用于所有品牌電腦。
推薦:《javascript基礎(chǔ)教程》《layUI教程》
layui中tips的使用
1、引入文件 layer.css 、 layer.js
2、參數(shù)介紹:
layer.tips(content, follow, options) - tips層 { content:tooltip內(nèi)容可以是str,也可以是html代碼 follow:依附的元素,一般用id表示 如果依附的元素是自己直接用this即可,如果是在其他元素的事件(比如點擊)里面,記得更改this指向。 options:tips的配置型[tips位置:1上;2右;3下;4左,字體的顏色] }
這3個是必填參數(shù),也同時具有l(wèi)ayer的其他基礎(chǔ)參數(shù),比如time(是否定時關(guān)閉),area(設(shè)置框的寬高),shadeClose(是否點擊遮罩層關(guān)閉)等。
3、代碼示例:
layer.tips(msg, '#id',{tips: 1},time:10000)
如果我們不想定時關(guān)閉,而是劃過顯示,劃出隱藏的效果,可以配合mouseenter、mouseleave事件即可,此時的time值為0,比如
<div class="content" id="content"> <label for="">你喜歡的人:</label> <input type="text" placeholder="請輸入……"> <i class="iconfont icon-combined-shape-copy tooltip-icon"></i> </div> <script type = "text/javascript" src="jquery-1.8.3.min.js"></script> <script type = "text/javascript" src="lib/layer.js"></script> <script> $(function(){ var tips; $('i.tooltip-icon').on({ mouseenter:function(){ var that = this; tips =layer.tips("<span style='color:#000;'>說明:只能選擇阿毛我,哈哈哈</span>",that,{tips:[2,'#fff'],time:0,area: 'auto',maxWidth:500}); }, mouseleave:function(){ layer.close(tips); } }); }) </script> /* $(".ack-img").hover(function () { layer.tips("智能組卷:每個用戶考試時抽到的試題及順序隨機組成", '.ack-img', {tips: 1}); });*/ $(function(){ var tips; $('.ack-img').on({ mouseenter:function(){ var that = this; tips =layer.tips("<span style='color:#000;'>智能組卷:每個用戶考試時抽到的試題及順序隨機組成</span>", that,{tips:[2,'#fff'],time:0,area: 'auto',maxWidth:500}); //tips = layer.tips("智能組卷:每個用戶考試時抽到的試題及順序隨機組成", that, {tips: 1}); }, mouseleave:function(){ layer.close(tips); } }); });