我正在使用这个简单的脚本,它将在页面上随机放置一个类为.random
的图像 - 效果很好。试图找出一种方法将这个应用于页面上的多个图像使用一个类,以便图像散布在页面上 - 现在如果它应用于多个图像,他们都使用相同的随机定位。随机位置多个图像
$(document).ready(function() {
var bodyWidth = document.body.clientWidth
var bodyHeight = document.body.clientHeight;
var randPosX = Math.floor((Math.random()*bodyWidth));
var randPosY = Math.floor((Math.random()*bodyHeight));
$('.random').css('left', randPosX);
$('.random').css('top', randPosY);
});
如果您使用选择'$( '随机')'这将适用于这样的类中的所有图像(即你所有的图像) - 可能你想遍历列表,并将位置分别应用到每个图像 – ochi