1. 程式人生 > >layer jquery 彈出層使用。

layer jquery 彈出層使用。

地址:http://sentsin.com/jquery/layer/


特別說明:事件需自己繫結,以下只展現呼叫程式碼。

//初體驗 layer.alert('內容')

//第三方擴充套件面板 layer.alert('內容', { icon: 1, skin: 'layer-ext-seaning' //該面板由layer.seaning.com友情擴充套件。關於面板的擴充套件規則,可以去API頁檢視 })

//詢問框 layer.confirm('您是如何看待前端開發?', { btn: ['重要','奇葩'], //按鈕 shade: false //不顯示遮罩 }, function(){ layer.msg('的確很重要', {icon: 1}); }, function(){ layer.msg('奇葩麼麼噠', {shift: 6}); });

//提示層 layer.msg('玩命提示中');

//墨綠深藍風 layer.alert('墨綠風格,點選確認看深藍', { skin: 'layui-layer-molv' //樣式類名 }, function(){ layer.alert('偶吧深藍style', { skin: 'layui-layer-lan', shift: 4 //動畫型別 }); });

//捕獲頁 layer.open({ type: 1, shade: false, title: false, //不顯示標題 content: $('.layer_notice'), //捕獲的元素 cancel: function(index){ layer.close(index); this.content.show(); layer.msg('捕獲就是從頁面已經存在的元素上,包裹layer的結構',{time: 5000}); } });

//頁面層 layer.open({ type: 1, area: ['420px', '240px'], //寬高 content: 'html內容' });

//自定頁 layer.open({ type: 1, skin: 'layui-layer-demo', //樣式類名 closeBtn: false, //不顯示關閉按鈕 shift: 2, shadeClose: true, //開啟遮罩關閉 content: '內容' });

//tips層 layer.tips('Hi,我是tips', '吸附元素選擇器,如#id');

//iframe層 layer.open({ type: 2, title: 'layer mobile頁', shadeClose: true, shade: 0.8, area: ['380px', '450px'], content: 'http://sentsin.com/layui/layer/' //iframe的url });

//iframe窗 layer.open({ type: 2, title: false, closeBtn: false, shade: [0], area: ['340px', '215px'], offset: 'rb', //右下角彈出 time: 2000, //2秒後自動關閉 shift: 2, content: ['test/guodu.html', 'no'], //iframe的url,no代表不顯示滾動條 end: function(){ //此處用於演示 layer.open({ type: 2, title: '很多時候,我們想最大化看,比如像這個頁面。', shadeClose: true, shade: false, maxmin: true, //開啟最大化最小化按鈕 area: ['640px', '450px'], content: 'http://www.layui.com?form=yidu' }); } });

//載入層 var index = layer.load(0, {shade: false}); //0代表載入的風格,支援0-2

//loading層 var index = layer.load(1, { shade: [0.1,'#fff'] //0.1透明度的白色背景 });

//小tips layer.tips('我是另外一個tips,只不過我長得跟之前那位稍有些不一樣。', '吸附元素選擇器', { tips: [1, '#3595CC'], time: 4000 });

//prompt層 layer.prompt({ title: '輸入任何口令,並確認', formType: 1 //prompt風格,支援0-2 }, function(pass){ layer.prompt({title: '隨便寫點啥,並確認', formType: 2}, function(text){ layer.msg('演示完畢!您的口令:'+ pass +' 您最後寫下了:'+ text); }); });

//tab層 layer.tab({ area: ['600px', '300px'], tab: [{ title: 'TAB1', content: '內容1' }, { title: 'TAB2', content: '內容2' }, { title: 'TAB3', content: '內容3' }] });

//相簿層 $.getJSON('/jquery/layer/test/photos.json?v='+new Date, function(json){ layer.photos({ photos: json //格式見API文件手冊頁 }); });



程式碼:

//資訊框-例1 layer.alert('見到你真的很高興', {icon: 9});

//資訊框-例2 layer.confirm('你確定你很帥麼?', {icon: 4}, function(index){ layer.close(index); alert('自戀狂'); });

//資訊框-例3 layer.msg('這是最常用的吧');

//資訊框-例4 layer.msg('不開心。。', {icon: 8});

//資訊框-例4 layer.msg('玩命賣萌中', function(){ //關閉後的操作 });

//頁面層-自定義 layer.open({ type: 1, title: false, closeBtn: false, shadeClose: true, skin: 'yourclass', content: '自定義HTML內容' });

//頁面層-佟麗婭 layer.open({ type: 1, title: false, closeBtn: false, area: ['516px', '620px'], skin: 'layui-layer-nobg', //沒有背景色 shadeClose: true, content: $('#tong') });

//iframe層-父子操作 layer.open({ type: 2, area: ['650px', '440px'], fix: false, //不固定 maxmin: true, content: 'test/iframe.html' });

//iframe層-多媒體 layer.open({ type: 2, title: false, area: ['630px', '360px'], shade: 0.8, closeBtn: false, shadeClose: true, content: 'http://player.youku.com/embed/XMjY3MzgzODg0' }); layer.msg('點選遮罩任意處關閉');

//iframe層-禁滾動條 layer.open({ type: 2, area: ['360px', '500px'], content: ['http://sentsin.com', 'no'] });

//載入層-預設風格 layer.load(); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格2 layer.load(1); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格3 layer.load(2); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格4 layer.msg('載入中', {icon: 16});

//打醬油 layer.msg('尼瑪,打個醬油', {icon: 13});

//tips層-上 layer.tips('上', '#id或者.class', { tips: [1, '#0FA6D8'] //還可配置顏色 });

//tips層-右 layer.tips('預設就是向右的', '#id或者.class');

//tips層-下 layer.tips('下', '#id或者.class', { tips: 2 });

//tips層-左 layer.tips('左邊麼麼噠', '#id或者.class', { tips: [4, '#78BA32'] });

//tips層-不銷燬之前的 layer.tips('不銷燬之前的', '#id或者.class', { tipsMore: true });

//預設prompt layer.prompt(function(val){ layer.msg('得到了'+val); });

//遮蔽瀏覽器滾動條 layer.open({ content: '瀏覽器滾動條已鎖', scrollbar: false });

//彈出即全屏 var index = layer.open({ type: 2, content: 'http://www.layui.com?form=full', area: ['300px', '195px'], maxmin: true }); layer.full(index);

//正上方 layer.msg('靈活運用offset', { offset: 0, shift: 6 });

//還該列舉什麼呢 layer.msg('等我想想…');

//資訊框-例1 layer.alert('見到你真的很高興', {icon: 9});

//資訊框-例2 layer.confirm('你確定你很帥麼?', {icon: 4}, function(index){ layer.close(index); alert('自戀狂'); });

//資訊框-例3 layer.msg('這是最常用的吧');

//資訊框-例4 layer.msg('不開心。。', {icon: 8});

//資訊框-例4 layer.msg('玩命賣萌中', function(){ //關閉後的操作 });

//頁面層-自定義 layer.open({ type: 1, title: false, closeBtn: false, shadeClose: true, skin: 'yourclass', content: '自定義HTML內容' });

//頁面層-佟麗婭 layer.open({ type: 1, title: false, closeBtn: false, area: ['516px', '620px'], skin: 'layui-layer-nobg', //沒有背景色 shadeClose: true, content: $('#tong') });

//iframe層-父子操作 layer.open({ type: 2, area: ['650px', '440px'], fix: false, //不固定 maxmin: true, content: 'test/iframe.html' });

//iframe層-多媒體 layer.open({ type: 2, title: false, area: ['630px', '360px'], shade: 0.8, closeBtn: false, shadeClose: true, content: 'http://player.youku.com/embed/XMjY3MzgzODg0' }); layer.msg('點選遮罩任意處關閉');

//iframe層-禁滾動條 layer.open({ type: 2, area: ['360px', '500px'], content: ['http://sentsin.com', 'no'] });

//載入層-預設風格 layer.load(); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格2 layer.load(1); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格3 layer.load(2); //此處演示關閉 setTimeout(function(){ layer.closeAll('loading'); }, 2000);

//載入層-風格4 layer.msg('載入中', {icon: 16});

//打醬油 layer.msg('尼瑪,打個醬油', {icon: 13});

//tips層-上 layer.tips('上', '#id或者.class', { tips: [1, '#0FA6D8'] //還可配置顏色 });

//tips層-右 layer.tips('預設就是向右的', '#id或者.class');

//tips層-下 layer.tips('下', '#id或者.class', { tips: 2 });

//tips層-左 layer.tips('左邊麼麼噠', '#id或者.class', { tips: [4, '#78BA32'] });

//tips層-不銷燬之前的 layer.tips('不銷燬之前的', '#id或者.class', { tipsMore: true });

//預設prompt layer.prompt(function(val){ layer.msg('得到了'+val); });

//遮蔽瀏覽器滾動條 layer.open({ content: '瀏覽器滾動條已鎖', scrollbar: false });

//彈出即全屏 var index = layer.open({ type: 2, content: 'http://www.layui.com?form=full', area: ['300px', '195px'], maxmin: true }); layer.full(index);

//正上方 layer.msg('靈活運用offset', { offset: 0, shift: 6 });

//還該列舉什麼呢 layer.msg('等我想想…');