![](/img/trans.png)
[英]How to show/hide text by clicking on image "Show" turning it to image "Hide"
[英]How to show/hide big image by clicking on thumbnails?
如何通過點擊縮略圖顯示/隱藏大圖像?
我需要這樣的
在這里試試JSFiddle http://jsfiddle.net/jitendravyas/Qhdaz/
是否可以只使用CSS。 如果沒有那么jQuery解決方案就可以了。
使用<a href=#">
即使它沒有在相同或新的選項卡中打開任何新頁面也是一件好事。
編輯:
我忘了添加。 它也應該在iPad上運行
看這個例子:
沒有預加載
HTML:
<div id="big-image">
<img src="http://lorempixel.com/400/200/sports/1/">
</div>
<div class="small-images">
<a href="http://lorempixel.com/400/200/sports/1/"><img src="http://lorempixel.com/100/50/sports/1/"></a>
<a href="http://lorempixel.com/400/200/fashion/1/" class=""><img src="http://lorempixel.com/100/50/fashion/1/"></a>
<a href="http://lorempixel.com/400/200/city/1/"><img src="http://lorempixel.com/100/50/city/1/"></a>
</div>
Javascript(jQuery)
$(function(){
$(".small-images a").click(function(e){
var href = $(this).attr("href");
$("#big-image img").attr("src", href);
e.preventDefault();
return false;
});
});
目前只有1個大圖像,當點擊A時,A的href被復制為大圖像的SRC。
實例: http : //jsfiddle.net/Qhdaz/1/
如果你不想在沒有額外DOM進展的情況下這樣做,你可以添加3個大圖像,並直接加載它們。 以上解決方案不預裝圖像,下面的功能會。
預加載
HTML:
<div id="big-image">
<img src="http://lorempixel.com/400/200/sports/1/">
<img src="http://lorempixel.com/400/200/fashion/1/">
<img src="http://lorempixel.com/400/200/city/1/">
</div>
<div class="small-images">
<img src="http://lorempixel.com/100/50/sports/1/">
<img src="http://lorempixel.com/100/50/fashion/1/">
<img src="http://lorempixel.com/100/50/city/1/">
</div>
使用Javascript:
$(function(){
$("#big-image img:eq(0)").nextAll().hide();
$(".small-images img").click(function(e){
var index = $(this).index();
$("#big-image img").eq(index).show().siblings().hide();
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.