The concrete example _javascript technique of JS spiral animation effect

Source: Internet
Author: User

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >


<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 ">
<title>Spiral</title>
<script type= "Text/javascript" src= "Js/jquery-1.5.js" ></script>

<body>
<script type= "Text/javascript" >
var spiral;
var yjq;
(function () {
YJQ = function (name,turns,duration,frame,count,decrease_time) {
$ (' style.enable_remove '). Remove ();
$ (' [id^=test] '). css ({' position ': ' absolute ', ' width ': ' Height ': ten, ' top ': +, ' Left ': +, ' background ': ' Black '});
Spiral (name+ ' 1 ', 600,300,300,300,turns,duration,frame);
Spiral (name+ ' 2 ', 300,0,300,300,turns,duration,frame);
Spiral (name+ ' 3 ', 0,300,300,300,turns,duration,frame);
Spiral (name+ ' 4 ', 300,600,300,300,turns,duration,frame);
$ (' # ' +name+ ' 1 '). CSS ({"-webkit-animation": name+ "1" +duration+ "Ms Linear" +count});
$ (' # ' +name+ ' 2 '). CSS ({"-webkit-animation": name+ "2" +duration+ "Ms Linear" +count});
$ (' # ' +name+ ' 3 '). CSS ({"-webkit-animation": name+ "3" +duration+ "Ms Linear" +count});
$ (' # ' +name+ ' 4 '). CSS ({"-webkit-animation": name+ "4" +duration+ "Ms Linear" +count});
var arg = arguments;
$ ("#" +name+ "4"). One (' Webkitanimationend ', function () {
if (duration<=0) {
Return
}
Arg.callee (Name,turns,duration-=decrease_time,frame,count,decrease_time);
});
}
Spiral = function (name,w1,h1,w2,h2,n,t,frame) {
var interval = t/frame;//per frame interval
var n;//circle Number
var i = 0;
var k;//initial Quadrant
var R = math.sqrt (Math.pow (w2-w1,2) +math.pow (h2-h1,2), 2);//Radius
var style= "@-webkit-keyframes" +name+ "{";
var styledom=$ ("<style class= ' Enable_remove ' ></style>");
if (w1>w2 && h1<=h2) {
K = 1;
}else if (w1<=w2 && h1K = 2;
}else if (w1<w2 && h1>=h2) {
K = 3;
}else {
K = 4;
}
for (Var t=0;t<t;t+=interval) {
var T1 = t% (t/n);
n = Math.floor (t/(t/n));
x = h2-r* (1-t1/t-n/n) *math.cos (2*math.pi*t1*n/t+math.pow ( -1,k) *math.atan (math.abs) w2-w1 (/Math.abs)) + (h2-h1 2?1:0) * (k%2?-1:1) *math.pi);
y = w2-r* (1-t1/t-n/n) *math.sin (2*math.pi*t1*n/t+math.pow ( -1,k) *math.atan (math.abs) w2-w1 (/Math.abs)) + (h2-h1 2?1:0) * (k%2?-1:1) *math.pi);
style+= (i++) *100/frame+ '%{top: ' +x+ ' px;left: ' +y+ ' px;} ';
}
style+= ' 100%{top: ' +w2+ ' px;left: ' +h2+ ' px;} ';
Styledom.html (style);
$ ("Head"). Append (Styledom);
};
})();
$ (function () {
var name = ' Test ';
var turns = Number of 5;//rotation rings
var duration = 2000;//Child animation time consuming
var decrease_time = 100;//time consuming reduction per child animation
var frame = 1000;//Child Animation frame number
var count = 2;//number of child animations performed
YJQ (Name,turns,duration,frame,count,decrease_time);
});
</script>
<div id= "Test1" ></div>
<div id= "Test2" ></div>
<div id= "Test3" ></div>
<div id= "Test4" ></div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.