demo.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** layer mobile demo */
  2. !function(){
  3. var demo = {};
  4. //扫二维码
  5. window.erweima && (erweima.onclick = function(){
  6. layer.open({
  7. type: 1,
  8. content: '<img src="./layer-mobile.png">'
  9. })
  10. });
  11. //小试牛刀
  12. demo.trys = function(index){
  13. //信息框
  14. if(index === 0){
  15. layer.open({
  16. content: '移动版和PC版不能同时存在同一页面'
  17. ,btn: '我知道了'
  18. });
  19. }
  20. //提示
  21. else if(index === 1){
  22. layer.open({
  23. content: 'hello layer'
  24. ,skin: 'msg'
  25. ,time: 2 //2秒后自动关闭
  26. });
  27. }
  28. //询问框
  29. else if(index === 2){
  30. layer.open({
  31. content: '您确定要刷新一下本页面吗?'
  32. ,btn: ['刷新', '不要']
  33. ,yes: function(index){
  34. location.reload();
  35. layer.close(index);
  36. }
  37. });
  38. }
  39. //底部对话框
  40. else if(index === 3){
  41. layer.open({
  42. content: '这是一个底部弹出的询问提示'
  43. ,btn: ['删除', '取消']
  44. ,skin: 'footer'
  45. ,yes: function(index){
  46. layer.open({content: '执行删除操作'})
  47. }
  48. });
  49. }
  50. //底部提示
  51. else if(index === 4){
  52. layer.open({
  53. content: '一个没有任何按钮的底部提示'
  54. ,skin: 'footer'
  55. });
  56. }
  57. //自定义标题风格
  58. else if(index === 5){
  59. layer.open({
  60. title: [
  61. '我是标题',
  62. 'background-color: #FF4351; color:#fff;'
  63. ]
  64. ,content: '标题风格任你定义。'
  65. });
  66. }
  67. //页面层
  68. else if(index === 6){
  69. layer.open({
  70. type: 1
  71. ,content: '可传入任何内容,支持html。一般用于手机页面中'
  72. ,anim: 'up'
  73. ,style: 'position:fixed; bottom:0; left:0; width: 100%; height: 200px; padding:10px 0; border:none;'
  74. });
  75. }
  76. //loading层
  77. else if(index === 7){
  78. layer.open({type: 2});
  79. }
  80. //loading带文字
  81. else if(index === 8){
  82. layer.open({
  83. type: 2
  84. ,content: '加载中'
  85. });
  86. }
  87. };
  88. if(window.trys){
  89. var tryas = trys.getElementsByTagName('a');
  90. for(var i = 0, len = tryas.length; i < len; i++){
  91. (function(i){
  92. tryas[i].addEventListener('click', function(){
  93. demo.trys(i);
  94. });
  95. }(i));
  96. };
  97. }
  98. }();