【发布时间】:2013-04-23 09:14:28
【问题描述】:
我有一个带有缩略图的画廊,当点击缩略图时,当前图像淡出,新图像淡入。
但是,我想停止多次点击,所以图像必须完全淡出才能点击新的缩略图。
如何使用下面的代码做到这一点?
非常感谢,
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>TEST</title>
<script type='text/javascript' src='jquery-1.9.1.js'></script>
<style type='text/css'>
#imageWrap{
position:relative;
overflow:hidden;
height:534px;
width:800px;
}
.next{
display:none;
}
#imageWrap img{
width: 800px;
position: absolute;
top: 0;
left: 0;
background-color: #000;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$('.thumbnail').on('click',function(){
$('#imageWrap').append('<img src="' + $(this).attr('src') + '" class="next" />');
$('#imageWrap .active').fadeOut(5500);
$('#imageWrap .next').fadeIn(4000, function(){
$('#imageWrap .active').remove();
$(this).addClass('active');
});
});
});//]]>
</script>
</head>
<body>
<img src="dimming/1.jpg" class="thumbnail" alt="A" width="40" height="40"/>
<img src="dimming/2.jpg" class="thumbnail" alt="B" width="40" height="40"/>
<img src="dimming/C.jpg" class="thumbnail" alt="C" width="40" height="40"/>
<img src="dimming/D.jpg" class="thumbnail"alt="D" width="40" height="40"/>
<img src="dimming/E.jpg" class="thumbnail" alt="E" width="40" height="40"/>
<div id="imageWrap">
<img src="dimming/C.jpg" alt="Main Image" width="800" height="534" class="active" />
</div>
</body>
</html>
【问题讨论】:
-
我实际上以一种非常简单的方式做到了这一点。单击时,我将一个 div 添加到图像容器中,该容器绝对位于容器内部。当所有动画都完成后,我只需删除这一层。它实际上可以通过多种方式完成,但这样我就不必为删除/添加侦听器而烦恼。
-
爱德华,你有这个例子吗,听起来很有趣。
标签: jquery