为了保持它的小巧和简单,当单击一个按钮时,所有的div都应该以随机的方向滑动,并且应该显示另一组新的div。
jQuery代码的基本演示:
$(document).ready(function() {
$("#toggle_value").click(function(){
$("#div1").show("fast");
$("#div2").show("fast");
$("#div3").show("fast");
});
});但这一切都是为了随机化效果。有什么解决方案吗?
发布于 2012-08-18 23:19:02
我会这样做:
http://jsfiddle.net/8uKt3/13/
$(document).ready(function() {
var $div = $('div'),
pos = [0, 0, 0, 500, 250, 100, 50, -500, -750, -1000, -1500], // Define your numbers
mypos1,
mypos2,
$me;
$("#toggle_value").click(function(){
$div.each(function(){
$me = $(this);
// Choose a value from each array randomly
mypos1 = pos[Math.floor(Math.random() * pos.length)];
mypos2 = pos[Math.floor(Math.random() * pos.length)];
// animate in a random direction in a random quantitya
$me.animate({
'top' : mypos1,
'left': mypos2
});
});
});
});发布于 2012-08-18 23:16:25
你可以这样做,假设你有3种可能的情况,div可能会滑走:
var rand = Math.random();
if (rand < .33) {
// Some animation
} else if (rand < .66) {
// Some other possible animation
} else {
// Final animation possibility
}发布于 2012-08-18 23:19:23
算法:
我的猜测是,你将在动画中引入延迟,使用完成所有返回的‘效果’,这看起来很好,但这应该是微不足道的
https://stackoverflow.com/questions/12019668
复制相似问题