我有以下代码,用于在单击缩略图时交换主图像:
$('#thumbs img').click(function(){
var imgsrc = $(this).attr('src');
$('#mainphoto img').fadeOut(function(){
$(this).attr('src', imgsrc).fadeIn();
});
});这里有一个有效的示例:http://clarkeconstructions.com.au/newsite/index.php?id=8
有些图片是肖像照片,有些是风景图片(如果您单击示例中的第二个缩略图)。
我希望能够向下滑动图像,使风景到肖像的过渡更平滑,但我不确定如何使用我目前的代码。
有没有人能给我一些提示,告诉我我会用什么语法来完成这个任务?
谢谢
发布于 2012-11-07 11:03:11
你可以使用的一个技巧是:
data容器W/H内的所有原始图像大小,同时将内部图像设置为H: 100%和W: 100%HTML:
<div id="projphotos">
<div id="mainphoto"><img src="" /></div><!--MAINPHOTO-->
<div id="projthumbs">
<img src="images/image_1.jpg" />
<img src="images/image_2.jpg" />
<img src="images/image_3.jpg" />
</div><!--PROJTHUMBS-->
</div>CSS:
#mainphoto{ /* roXon */
border-radius: 5px 5px 5px 5px;
box-shadow: 0 0 5px #888888;
padding: 10px;
display:inline-block;
*dispaly:inline;
zoom:1;
width:0;
height:0;
}
#mainphoto img{
position:relative;
margin:0 auto;
vertical-align:middle;
width:100%;
height:100%;
}
#projphotos img {
/* removed properties */
background-image: url("tmpimages/billie_holiday.png");
}父图像(存储/使用原始图像大小来动画主图像:)
$(window).load(function(){
var imgs = $('#projthumbs img');
$.each(imgs, function(i, el){
$('<img>', {"src": this.src}).load(function(){
$(el).data({'h': this.height, 'w': this.width});
if(i===0){
$(el).click();
}
});
});
$('#projthumbs img').click(function(){
var imgsrc = this.src;
var orgSize = { h: $(this).data('h'), w: $(this).data('w') };
$('#mainphoto img').stop().fadeTo(400,0,function(){
$(this).attr('src', imgsrc).fadeTo(400,1);
$('#mainphoto').animate({height: orgSize.h, width: orgSize.w },400);
});
});
$('#projthumbs img').eq(0).click();
});发布于 2012-11-07 10:57:49
试试这个,下面是工作示例:http://jsfiddle.net/mjaA3/216/
jQuery:
var thumbs = $('ul.thumbHolder li');
var bigImg = $('.mask img');
//You need to mask your image for creating sliding it down effect.
thumbs.first().addClass('selected');
thumbs.click(function() {
var imgsrc = $(this).children('img').attr('src');
bigImg.animate({'top':'266px'},300,function() {
bigImg.attr('src', imgsrc ).animate({'top':'0px'},300);
});
thumbs.removeClass('selected');
$(this).addClass('selected');
});html:
<div class="mask">
<img width="270" src="http://sample1.jpg" />
</div>
<ul class="thumbHolder">
<li>
<img width="20" src="http://sample1.jpg" />
</li>
<li>
<img width="20" src="http://sample2.jpg" />
</li>
<li>
<img width="20" src="http://sample3.jpg" />
</li>
</ul>css:
.mask {
overflow:hidden; position:relative; left:0; top:0;
float:left; margin:40px; width:400px; height:266px;
}
.mask img { position:absolute; top:0px;left:0px; }不使用src的替代方法:http://jsfiddle.net/mjaA3/197/
https://stackoverflow.com/questions/13262266
复制相似问题