【发布时间】:2011-08-26 06:02:24
【问题描述】:
我有一个幻灯片,它只是改变照片。我需要在每张照片的顶部添加一个新的 div 框。目前jquery 代码只需要#slideshow 和.active。如何修改它以获取新的 div 类“.newbox”(第一张照片为 .newbox1,第二张照片为 .newbox2,依此类推)。每次不同的盒子必须出现在不同的照片之上。这是我的照片幻灯片 jquery 代码:
function slideSwitch() {
var $active = $('#slideshow DIV.active');
if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
// use this to pull the divs in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow DIV:first');
// uncomment below to pull the divs randomly
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
</script>
我的html:
div id="slideshow">
<div class="active">
<a href="http://www.mylink.com/" target="_blank"><img src="http://route/img.jpg" alt="alt" /></a>
<div class="newbox"></div>
</div>
【问题讨论】:
标签: jquery