Javascript 使用jquery设置方向动画
我用响应脚本创建了雪花。一切都很好,没问题。但是我想增强雪花的方向,比如从左到右,从右到左,从上到下。我试过了,但我不确定是哪里出的错 这是 Javascript:Javascript 使用jquery设置方向动画,javascript,jquery,css,Javascript,Jquery,Css,我用响应脚本创建了雪花。一切都很好,没问题。但是我想增强雪花的方向,比如从左到右,从右到左,从上到下。我试过了,但我不确定是哪里出的错 这是 Javascript: var fallingSpeed = Math.floor(Math.random() * 5 + 1); var movingDirection = Math.floor(Math.random() * 2); var currentTop = parseInt(jQ
var fallingSpeed = Math.floor(Math.random() * 5 + 1);
var movingDirection = Math.floor(Math.random() * 2);
var currentTop = parseInt(jQuery(this).css('top'));
var currentLeft = parseInt(jQuery(this).css('left'));
jQuery(this).css('top', currentTop + fallingSpeed);
alert(currentLeft);
//
//alert(movingDirection);
if (movingDirection === 0) {
jQuery(this).css('left', currentLeft + fallingSpeed);
} else {
// set the snow move to left
jQuery(this).css('left', currentLeft + -(fallingSpeed));
}
如何将薄片从左向右和从右向左移动?
任何建议都很好
谢谢。尝试jquery animate的
步骤
回调函数:
$(function(){
var drop = $('.drop').detach();
function create(){
var clone = drop
.clone()
.appendTo('.container')
.css('left', Math.random()*$(document).width()-20)
.html('*')
.animate(
{'top': $(document).height()-20},
{
duration: Math.random(1000)+8000,
complete:function(){
$(this).fadeOut(200,function(){$(this).remove();});
},
step:function (currentTop){
var fallingSpeed = Math.floor(Math.random() * 5 + 1);
var movingDirection = Math.floor(Math.random() * 2);
var currentTop = parseInt(jQuery(this).css('top'));
var currentLeft = parseInt(jQuery(this).css('left'));
jQuery(this).css('top', currentTop + fallingSpeed);
if (movingDirection === 0) {
jQuery(this).css('left', currentLeft + fallingSpeed);
} else {
// set the snow move to left
jQuery(this).css('left', currentLeft + -(fallingSpeed));
}
}
});
}
是的,雪花……让我想起了90年代;)[HOT]请访问此url-