window.onload = rolloverInit;
//加载窗体时触发事件

function rolloverInit()...{
for (var i=0; i<document.images.length; i++)...{
if(document.images[i].parentNode.tagName=="A")...{
setupRollover(document.images[i]);
}
}
}
//对所有包含超级连接的图片执行滚动设置


function setupRollover(thisImage)...{
thisImage.outImage = new Image();
thisImage.outImage.src = thisImage.src;
thisImage.onmouseout = rollOut;
thisImage.overImage = new Image();
thisImage.overImage.src = thisImage.id + "_on.jpg";
thisImage.onmouseover = rollOver;
}
//为图片设置了out和over两种模式和相应的图片,可根据需要实际添加或修改


function rollOver()...{
this.src = this.overImage.src;
}

function rollOut()...{
this.src = this.outImage.src;
}相应在HTML中要对脚本进行引用,同时需要滚动效果的图片应包含在超连接<a herf="..."></a>中
本文介绍了一种使用JavaScript实现图片滚动效果的方法。通过监听鼠标进出事件,动态切换图片源,达到预设的视觉效果。适用于带有超链接的图片元素。
129

被折叠的 条评论
为什么被折叠?



