HTML頁面:javascript
頁面CSS:
JS:java
var $first=$('#first');
var $second=$('#second');
(function firstMove(){
$first.animate({
"left":220,
"top": 0,
},400,"linear",function(){
$first.animate({
"left":220,
"top":220
},400,"linear",function(){
$first.animate({
"left":0,
"top":220
},400,"linear",function(){
$first.animate({
"left":0,
"top":0
},400,"linear",function(){
firstMove();
});
});
});
});
})();
(function secondMove(){
$second.animate({
"right":220,
"bottom":0
},400,"linear",function(){
$second.animate({
"right":220,
"bottom":220
},400,"linear",function(){
$second.animate({
"right":0,
"bottom":220
},400,"linear",function(){
$second.animate({
"right":0,
"bottom":0
},400,"linear",function(){
secondMove();
});
});
});
});
})();jquery
/*Javascript代碼片斷*/
var $first=$('#first');
var $second=$('#second');
function h(x, currentTime, beginningValue, changeValue, duration){
if(beginningValue){
if(x<0.25){
return (0.25-x)*4;
}else if(x<0.5){
return 0;
}else if(x<0.75){
return (x-0.5)*4;
}
return 1;
}else{
if(x<0.25){
return x*4;
}else if(x<0.5){
return 1;
}else if(x<0.75){
return (0.75-x)*4;
}
return 0;
}
}
function v(x, currentTime, beginningValue, changeValue, duration){
if(beginningValue){
if(x<0.25){
return 1;
}else if(x<0.5){
return (0.5-x)*4;
}else if(x<0.75){
return 0;
}
return (x-0.75)*4;
}else{
if(x<0.25){
return 0;
}else if(x<0.5){
return (x-0.25)*4;
}else if(x<0.75){
return 1;
}
return (1-x)*4;
}
}
$.extend( $.easing,
{
"v":v,
"h":h
});
(function firstMove(){
$first.animate({
"left":220,
"top":220
},{
duration: 1600,
specialEasing: {
left: 'h',
top: 'v'
},
complete: function() {
firstMove();
}
});
})();
(function secondMove(){
$second.animate({
"left":0,
"top":0
},{
duration: 1600,
specialEasing: {
left: 'h',
top: 'v'
},
complete: function() {
secondMove();
}
});
})();jsp