<style>
div{position:absolute}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function () {
$('div').each(function () {
var o = $(this);
var r = Math.random();
donghua(o.data('dir', r > 0.5 ? 1 : -1));
}); });
function donghua(o) {
var dir = o.data('dir'), v = Math.max(document.body.clientWidth, document.documentElement.clientWidth)
, left = parseInt(o.css('left'), 10), reset = (dir < 0 && left <= 0) || (dir > 0 && left >= v);
if (reset) o.css('left', dir < 0 ? v : 0);
o.animate({ left: (dir < 0 ? '-' : '+') + "=10px" }, '3000', 'linear', function () { donghua($(this)) });
};</script>
<div style="top:20px">e</div>
<div style="top:40px">w</div>
<div style="top:60px">2</div>
div{position:absolute}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function () {
$('div').each(function () {
var o = $(this);
var r = Math.random();
donghua(o.data('dir', r > 0.5 ? 1 : -1));
}); });
function donghua(o) {
var dir = o.data('dir'), v = Math.max(document.body.clientWidth, document.documentElement.clientWidth)
, left = parseInt(o.css('left'), 10), reset = (dir < 0 && left <= 0) || (dir > 0 && left >= v);
if (reset) o.css('left', dir < 0 ? v : 0);
o.animate({ left: (dir < 0 ? '-' : '+') + "=10px" }, '3000', 'linear', function () { donghua($(this)) });
};</script>
<div style="top:20px">e</div>
<div style="top:40px">w</div>
<div style="top:60px">2</div>
<style>
div{position:absolute}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function () {
$('div').each(function () {
var o = $(this);
var r = Math.random();
donghua(o, r > 0.5 ? -1 : 1);
}); });
function donghua(o, r) {
o.animate({ left: (r < 0 ? '-' : '+') + "=10px" }, '3000', 'linear', function () { donghua($(this), -1 * r) });
}
</script>
<div style="top:20px">e</div>
<div style="top:40px">w</div>
<div style="top:60px">2</div>