我正在尝试让 2 个不同的脚本一起工作..
一个是一个简单的缩略图切换脚本,它根据单击的缩略图更改大图像,来自http://bonrouge.com/br.php?page=imageswitch
另一个是图像缩放脚本,它根据鼠标悬停的位置缩放到更大的图像,来自http://www.dynamicdrive.com/dynamicindex4/featuredzoomer.htm
问题是它总是显示第二张图像,无论缩略图是切换到第一张还是第二张。我认为这与 div 重叠或其他有关。
这是组合代码:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#image-switch ul {
margin:0 0 0 20px;
color:red;
list-style-type:none;
}
#image-switch li {
padding:10px;
}
#image-switch #two, #image-switch #three, #image-switch #four, #image-switch #five {
display:none;
}
#radiobs {
width:150px;
position:relative;
margin:0;
}
#radiobs input {
margin:0;
padding:0;
position:absolute;
margin-left:6em;
width:15px;
}
</style>
<style type="text/css">
.magnifyarea{ /* CSS to add shadow to magnified image. Optional */
box-shadow: 5px 5px 7px #818181;
-webkit-box-shadow: 5px 5px 7px #818181;
-moz-box-shadow: 5px 5px 7px #818181;
filter: progid:DXImageTransform.Microsoft.dropShadow(color=#818181, offX=5, offY=5, positive=true);
background: white;
}
</style>
</head>
<body>
<div id="image-switch">
<div class="fright">
<div id="one">
<img id="image1" src="redsmall.jpg" height="193" width="150" alt="redsmall" />
<p>This is a red one.</p>
</div>
<div id="two">
<img id="image2" src="bluesmall.jpg" height="193" width="150" alt="bluesmall" />
<p>This is a blue one.</p>
</div>
</div>
</div>
<ul>
<li><a onclick="switch1('one');">first frame</a></li>
<li><a onclick="switch1('two');">second frame</a></li>
</ul>
<div class="clear"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="featuredimagezoomer.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#image1').addimagezoom({
zoomrange: [3, 10],
magnifiersize: [450,350],
magnifierpos: 'right',
cursorshade: true,
largeimage: 'redbig.jpg' //<-- No comma after last option!
})
$('#image2').addimagezoom({
zoomrange: [3, 10],
magnifiersize: [450,350],
magnifierpos: 'right',
cursorshade: true,
largeimage: 'bluebig.jpg' //<-- No comma after last option!
})
})
</script>
<script type="text/javascript">
function switch1(div) {
var options, obj, id;
if (document.getElementById(div)) { // change this to div instead of 'one'
options=['one','two','three','four'];
for (var i=0; i<options.length; i++) {
id = options[i]; // caching the array item is good practice bc array/object access is slow
obj=document.getElementById(id);
if (!obj) { continue; } // make sure the obj exists
obj.style.display = (id === div) ? "block" : "none";
}
}
}
//
</script>
</body>
</html>
如果有人知道出了什么问题,我保证我会以你的名字命名我的长子!