[英]animating elements a random negative or positive amount
我正在尝试使用math.random通过math.random随机地对这些单词的字符进行动画处理,但它不起作用。 我的数学演示有问题吗
$('.reverse_button').on('click', function(){
var chars = $('.reverse_body').blast({
delimiter: 'character'
});
var moveup=parseInt((Math.random()* document.body.clientHeight) - document.body.clientHeight);
var moveleft=parseInt((Math.random()* document.body.clientWidth) - document.body.clientWidth);
chars.each(function(idx,obj) {
$(obj).animate({
left: moveleft,
top: moveup
});
});
});
这就是我要首先获得的工作。 这里有错误。
$('.reverse_button').on('click', function(){
var chars = $('.reverse_body').blast({
delimiter: 'character'
});
chars.each(function() {
$(this).animate({
left: 100,
top: 100
}, 500);
});
});
@凯文
我需要给受影响的元素一个相对的位置。 这是工作代码和演示。
$('.reverse_button').on('click', function(){
var chars = $('.reverse_body').blast({
delimiter: 'character'
});
chars.each(function() {
var moveup=parseInt((Math.random()* document.body.clientHeight) - document.body.clientHeight);
var moveleft=parseInt((Math.random()* document.body.clientWidth) - document.body.clientWidth);
$(this).css({
position: 'relative',
left: 0
})
.animate({
left: moveleft,
top: moveup
}, 1500);
});
});
但是,它仍然不是动画负数,有人知道创建随机负数的公式吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.