最佳答案
function fx(o) {
var $o = $(o);
$o.html($o.text().replace(/([\S])/g, "<span>$1</span>"));
$o.css("position", "relative");
$("span", $o).each(function(i) {
var newTop = Math.floor(Math.random()*500)*((i%2)?1:-1);
var newLeft = Math.floor(Math.random()*500)*((i%2)?1:-1);
$(this).css({position: "relative",
opacity: 1,
fontSize: 12,
top: 0,
left: 0
}).animate({
opacity: 0,
fontSize: 84,
top: newTop,
left:newLeft
},1000);
});
}
您可以在 http://jsfiddle.net/dNXVx/37/ 查看代码的运行情况。
关于javascript - 使用 jQuery 从字面上将文本分解到随机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9656353/