load.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*!
  2. * jQuery loading Plugin v1.0.1
  3. *
  4. * Copyright 2017 Nick Han
  5. */
  6. (function (factory) {
  7. if (typeof define === 'function' && define.amd) {
  8. // AMD
  9. define(['jquery'], factory);
  10. } else if (typeof exports === 'object') {
  11. // CommonJS
  12. factory(require('jquery'));
  13. } else {
  14. // Browser globals
  15. factory(jQuery);
  16. }
  17. }(function ($) {
  18. //给窗口添加滚动事件,在滚动时遮罩跟着元素移动
  19. $(window).bind("scroll",function() {
  20. var masks = $(".mask");
  21. for (var i = 0; i < masks.length; i++) {
  22. var ele_id = $(masks[i]).attr("ele");
  23. var eleTop= $(ele_id).offset().top;
  24. var gun = $(document).scrollTop();
  25. var top = eleTop-gun;
  26. $(masks[i]).css({
  27. "top": top+'px'
  28. });
  29. }
  30. });
  31. //timeout cache
  32. var cache = {};
  33. var mask_html = "<div id='lot3d_loading_text'>数据加载中...</div>";
  34. /*
  35. * full screen loading mask
  36. */
  37. $.mask_fullscreen = function(timeout){
  38. if($(".mask[ele=full_screen]").length > 0){
  39. return;
  40. }
  41. //禁止滚动
  42. // $("body").addClass("scroll-off");
  43. var mask = '<div id="lot3d_loading_mask_html" class="mask" ele="full_screen">'+mask_html+'</div>';
  44. $("body").append(mask);
  45. clearTimeout(cache["full_screen"]);
  46. if(timeout && timeout > 0){
  47. var s = setTimeout(function(){
  48. $(".mask[ele=full_screen]").remove();
  49. $("body").removeClass("scroll-off");
  50. }, timeout);
  51. cache["full_screen"] = s;
  52. }
  53. }
  54. /*
  55. * close all loading mask
  56. */
  57. $.mask_close_all = function(){
  58. $(".mask").remove();
  59. }
  60. $.mask_text = function(text){
  61. $("#lot3d_loading_text")[0].innerText = text;
  62. }
  63. $.mask_html = function(html){
  64. mask_html = html;
  65. }
  66. }));