0
這是我如何調用Java腳本函數在我的HTML頁面: -圖片滾動不工作
<script type="text/javascript" src="imagerollover.js"></script>
</script>
<script type="text/javascript">
//Following function should be called at the end of the page:
imagerollover();
</script>
</head>
<body>
.
.
.
這是我imagerollover.js: -
function imagerollover(){
var allimages=document.getElementsByTagName("img")
var preloadimages=[]
for (var i=0; i<allimages.length; i++){
if (allimages[i].getAttribute("data-over")){ //if image carries "data-over" attribute
preloadimages.push(new Image()) //preload "over" image
preloadimages[preloadimages.length-1].src=allimages[i].getAttribute("data-over")
allimages[i].onmouseover=function(){
this.src=this.getAttribute("data-over")
}
allimages[i].onmouseout=function(){
this.src=this.getAttribute("data-out")
}
} //end if
} //end for loop
}
//Usage: Call following function at the end of the page:
//imagerollover()
圖片代碼:
<img src="knitting1.jpg"
data-over="knitting2.jpg"
data-out="knitting1.jpg"
alt="Logo" width="400px" height="90" align="middle" />
此外,我的網站的根文件夾中存在兩個圖像knitting1.jpg和knitting2.jpg。我不知道什麼是錯的。請幫忙。謝謝。
我在開始的時候放置一個警告imagerollover.js文件中。它正在呼叫,但它沒有顯示任何翻滾效果。爲什麼?
你的''標籤是什麼樣子? – Blender 2012-08-19 05:27:36
– Serenity 2012-08-19 05:36:30