【发布时间】:2017-11-09 23:29:11
【问题描述】:
晚上好,我正在尝试创建允许用户将鼠标悬停在拇指上的功能,放大的图像将显示在占位符中。我还创建了使用数组在横幅广告中旋转的函数。我的问题是我无法执行任何脚本,我不明白为什么,因为我是 JS 的新手。有什么帮助吗?
<script type = "text/javascript">
window.onload = rotate;
var banners = ["banner1.gif","banner2.gif","banner3.gif","banner4.gif"];
for (var i =0; i<banners.length; i++) {
banners[i] = new Image();
}
function rotate() {
var i;
if (i == banners.length) {
i = 0;
}
document.getElementById("banner").src = banners[i];
setTimeout(rotate, 3 * 1000);
}
}
var fullSize = ["FrenchQuarter","GoldenGateBridge", "NazarethBay", "TheAlamo"];
//declare each as an image object
//declare each one of the array elemant as an image object
for (var i =0; i<fullSize.length; i++) {
fullSize[i] = new Image(279,373);
}
var width = 0;
var speed = 3;
var interval = null;
window.addEventListener("load", start, false);
function start() {
document.getElementById("smallfq").onmouseover=function() {displayFull(0)};
document.getElementById("smallggb").onmouseover=function() {displayFull(1)};
document.getElementById("smallNaz").onmouseover=function() {displayFull(2)};
document.getElementById("smallAlamo").onmouseover=function() {displayFull(3)};
}
function displayFull(n) {
document.getElementByid("placeholder").setAttribute("style", "width:0px; height:0px;");
width=0;
document.getElementByid("placeholder").src=fullSize[n].src;
}
对应的HTML如下:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Assignment 3</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script type ="text/javascript" src = "Assignment3.js"></script>
</head>
<body>
<div id = "bannerDiv">
<img src = "banner3.gif" id = "banner" alt = "banner" >
</div>
<br>
<div id = "placeholderdiv">
<br>
<img id = "placeholder" src = "placeholder.jpg" alt = "placeholder">
<p>Move your Mouse over one of the icons to see and enlarged image</p>
<br>
</div>
<br>
<div id = "thumbs">
<img src = "FrenchQuarter_small.jpg" id = "smallfq" alt = "smallFrenchQuarter">
<img src = "GoldenGateBridge_small.jpg" id = "smallggb" alt = "smallggb" >
<img src = "NazarethBay_small.jpg" id = "smallNaz" alt = "smallNaz" >
<img src = "TheAlamo_small.jpg" id = "smallAlamo" alt = "SmallAlamo" onmouseover ="function() {displayFull(3)}" >
</div>
<br>
</body>
</html>
【问题讨论】:
标签: javascript user-defined-functions