更改鼠标悬停时的背景图像,如facebook专辑。当你悬停任何专辑时,你可以随机浏览3 4图像。我可以在jquery中执行此操作。我尝试这个,但它不能像我想做的那样工作
function randomPick(arr) {
var selected = arr[Math.floor(Math.random()*arr.length)]
return selected;
}
images =
[
"image1.png",
"image2.png",
"image3.png",
"image4.png",
"image5.png"
]
function randomHover () {
var myImage = document.getElementById('hover');
var selImage = randomPick(images);
myImage.src = selImage;
}
function resetState() {
var myImage = document.getElementById('hover');
myImage.src = "something.png";
}
答案 0 :(得分:0)
尝试将返回值转换为如下整数:
arr[parseInt(Math.floor(Math.random()*arr.length))]