JSDM

HTML

 
1
<p><strong>Click to open/close the preloader.</strong><br>Completely customizable (colors, radius, number of dots, size, etc.).<br>One JavaScript call opens or closes the preloader elegantly.</p>

CSS

xxxxxxxxxx
13
 
1
/* none of this CSS is necessary for the preloader */
2
body {
3
  background-color: #ccc;
4
  font-family: sans-serif;
5
  font-size: 18px;
6
}
7
p {
8
  position: fixed;
9
  bottom: 0;
10
  text-align: center;
11
  width: 100%;
12
  padding: 0 10px 4px 10px;
13
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

x
 
1
//Pure JS, completely customizable preloader from GreenSock.
2
//Once you create an instance like var preloader = new GSPreloader(), call preloader.active(true) to open it, preloader.active(false) to close it, and preloader.active() to get the current status. Only requires TweenLite and CSSPlugin (http://www.greensock.com/gsap/)
3
var preloader = new GSPreloader({
4
  radius:42, 
5
  dotSize:15, 
6
  dotCount:10, 
7
  colors:["#61AC27","#555","purple","#FF6600"], //have as many or as few colors as you want.
8
  boxOpacity:0.2,
9
  boxBorder:"1px solid #AAA",
10
  animationOffset: 1.8, //jump 1.8 seconds into the animation for a more active part of the spinning initially (just looks a bit better in my opinion)
11
});
12
13
//open the preloader
14
preloader.active(true);
15
16
//for testing: click the window to toggle open/close the preloader
17
document.onclick = document.ontouchstart = function() {
18
  preloader.active( !preloader.active() );
19
};
20
21
//this is the whole preloader class/function
22
function GSPreloader(options) {
23
  options = options || {};
24
  var parent = options.parent || document.body,
25
      element = this.element = document.createElement("div"),
26
      radius = options.radius || 42,
27
      dotSize = options.dotSize || 15,
28
      animationOffset = options.animationOffset || 1.8, //jumps to a more active part of the animation initially (just looks cooler especially when the preloader isn't displayed for very long)
29
      createDot = function(rotation) {
30
          var dot = document.createElement("div");
31
        element.appendChild(dot);
32
        TweenLite.set(dot, {width:dotSize, height:dotSize, transformOrigin:(-radius + "px 0px"), x: radius, backgroundColor:colors[colors.length-1], borderRadius:"50%", force3D:true, position:"absolute", rotation:rotation});
33
        dot.className = options.dotClass || "preloader-dot";
34
        return dot; 
35
      }, 
36
      i = options.dotCount || 10,
37
      rotationIncrement = 360 / i,
38
      colors = options.colors || ["#61AC27","black"],
39
      animation = new TimelineLite({paused:true}),
40
      dots = [],
41
      isActive = false,
42
      box = document.createElement("div"),
43
      tl, dot, closingAnimation, j;
44
  colors.push(colors.shift());
45
  
46
  //setup background box
47
  TweenLite.set(box, {width: radius * 2 + 70, height: radius * 2 + 70, borderRadius:"14px", backgroundColor:options.boxColor || "white", border: options.boxBorder || "1px solid #AAA", position:"absolute", xPercent:-50, yPercent:-50, opacity:((options.boxOpacity != null) ? options.boxOpacity : 0.3)});
48
  box.className = options.boxClass || "preloader-box";
49
  element.appendChild(box);
50
  
51
  parent.appendChild(element);
52
  TweenLite.set(element, {position:"fixed", top:"45%", left:"50%", perspective:600, overflow:"visible", zIndex:2000});
53
  animation.from(box, 0.1, {opacity:0, scale:0.1, ease:Power1.easeOut}, animationOffset);
54
  while (--i > -1) {
55
    dot = createDot(i * rotationIncrement);
56
    dots.unshift(dot);
57
    animation.from(dot, 0.1, {scale:0.01, opacity:0, ease:Power1.easeOut}, animationOffset);
58
    //tuck the repeating parts of the animation into a nested TimelineMax (the intro shouldn't be repeated)
59
    tl = new TimelineMax({repeat:-1, repeatDelay:0.25});
60
    for (j = 0; j < colors.length; j++) {
61
      tl.to(dot, 2.5, {rotation:"-=360", ease:Power2.easeInOut}, j * 2.9)
62
        .to(dot, 1.2, {skewX:"+=360", backgroundColor:colors[j], ease:Power2.easeInOut}, 1.6 + 2.9 * j);
63
    }
64
    //stagger its placement into the master timeline
65
    animation.add(tl, i * 0.07);
66
  }
67
  if (TweenLite.render) {
68
    TweenLite.render(); //trigger the from() tweens' lazy-rendering (otherwise it'd take one tick to render everything in the beginning state, thus things may flash on the screen for a moment initially). There are other ways around this, but TweenLite.render() is probably the simplest in this case.
69
  }
70
  
71
  //call preloader.active(true) to open the preloader, preloader.active(false) to close it, or preloader.active() to get the current state.
72
  this.active = function(show) {
73
    if (!arguments.length) {
74
      return isActive;
75
    }
76
    if (isActive != show) {
77
      isActive = show;
78
      if (closingAnimation) {
79
        closingAnimation.kill(); //in case the preloader is made active/inactive/active/inactive really fast and there's still a closing animation running, kill it.
80
      }
81
      if (isActive) {
82
        element.style.visibility = "visible";
83
        TweenLite.set([element, box], {rotation:0});
84
        animation.play(animationOffset);
85
      } else {
86
        closingAnimation = new TimelineLite();
87
        if (animation.time() < animationOffset + 0.3) {
88
          animation.pause();
89
          closingAnimation.to(element, 1, {rotation:-360, ease:Power1.easeInOut}).to(box, 1, {rotation:360, ease:Power1.easeInOut}, 0);
90
        }
91
        closingAnimation.staggerTo(dots, 0.3, {scale:0.01, opacity:0, ease:Power1.easeIn, overwrite:false}, 0.05, 0).to(box, 0.4, {opacity:0, scale:0.2, ease:Power2.easeIn, overwrite:false}, 0).call(function() { animation.pause(); closingAnimation = null; }).set(element, {visibility:"hidden"});
92
      }
93
    }
94
    return this;
95
  };
96
}
97
98
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................