下面的代碼有效,直到我在圖像周圍添加一個鏈接。它可以在刪除鏈接和刪除js和css中'幻燈片img'之間的'a'的情況下使用。向此javascript幻燈片組添加鏈接的正確方法是什麼?
頭:
<script type="text/javascript">
function slideSwitch() {
var $active = $('#slideshow a img.active');
if ($active.length == 0) $active = $('#slideshow a img:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow a img:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
var $first = $('#slideshow a img:first');
$first.addClass('active');
setInterval("slideSwitch()", 4500);
});
</script>
身體:
<div id="slideshow">
<a href="/samplehome"><img src="/img/slide_three.jpg" width="948px" height="432px" border="0" alt="Three"/></a>
<a href="/samplehome"><img src="/img/slide_two.jpg" width="948px" height="432px" border="0" alt="Two"/></a>
<a href="/samplehome"><img src="/img/slide_one.jpg" width="948px" height="432px" border="0" alt="Ease In Motion"/></a>
</div>
在CSS:
#slideshow, #sub_slideshow {
position:relative;
height:432px;
width: 948px;
display: block;
margin: 0;
padding: 0;
float: right;
}
#slideshow a img, #sub_slideshow a img {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
}
#slideshow a img.active, #sub_slideshow a img.active {
z-index:10;
opacity:1.0;
}
#slideshow a img.last-active , #sub_slideshow a img.last-active {
z-index:9;
}
輝煌,那就是訣竅。謝謝! – sterling