loading.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*进度条*/
  2. //杨俊源
  3. //命名空间
  4. Namespace.register("U.Control.Bar");
  5. //调用的主函数 返回Content
  6. //U.Control.Bar.loadImg(src,width,height)
  7. U.Control.Bar.Box = function () {
  8. return document.body.appendChild(U.Control.Bar.loadImg("http://fs.1473.cn/3e5b78e0-6ded-4386-b643-dd27d15fc007.jpg", 500, 600)); //传参(src,width,height)
  9. }
  10. //加载图片
  11. U.Control.Bar.loadImg = function (imgUrl, width, height) {
  12. //var content = $("#"+content)[0];
  13. //创建一个div
  14. var content = $$("div", { "id": "Image", "style": { "cssText": "width:" + width + "px;height:" + height + "px"} });
  15. // content.style.position = "relative";
  16. content.style.position = "absolute";
  17. //div的底层
  18. var bg = $$("img", { "style": { "cssText": "width:100%;height:100%;opacity:1;position:absolute;"} }, content);
  19. //div遮罩层
  20. var divs = $$("div", { "style": { "cssText": "width:100%;height:100%;background:#fff;opacity: 1;transition: 0.8s all;position: relative;"} }, content);
  21. //进度条。。。
  22. var progress = $$("div", { "style": { "cssText": "width: 100%;height: 28px;border-radius: 16px;background: rgb(33, 176, 252);position: absolute;display: inline-block;top: 50%;margin-top: -14px;"} }, divs);
  23. var div = $$("div", { "style": { "cssText": "width: 99%;height: calc(100% - 10px);margin: auto;border-radius: 16px;background: rgb(255, 255, 255);margin-top: 4px;border: 1px solid #fff;"} }, progress);
  24. var bar = $$("div", { "style": { "cssText": "width: 0%;height: 100%;background: rgb(33, 176, 252);border-radius: 16px;transition: 4s all;"} }, div);
  25. //var barA = $$("div",{"style":{"cssText":"float:right"}},bar);
  26. //var barF = $$("a",{"innerHTML":"1"},barA);
  27. //var barFB = $$("a",{"innerHTML":"%"},barA);
  28. //进度条上下居中
  29. //progress.style.top = (parseInt(content.style.width)-progress.offsetHeight)/2+"px";
  30. setTimeout(function () { bar.style.width = "98%"; }, 1);
  31. //$(bar).animate({"width":"98%"},1000);
  32. //bar.style.width="98%";
  33. var img = new Image();
  34. img.src = imgUrl;
  35. //图片加载完成
  36. img.onload = function () {
  37. $(bar).animate({ "width": "100%" }, 100);
  38. setTimeout(function () { divs.style.cssText += "opacity:0"; U.Alert("加载完成"); }, 2000);
  39. bg.src = img.src;
  40. }
  41. return content;
  42. }
  43. /*U.Control.Bar End*/