2011-02-12 101 views

回答

4

http://jsfiddle.net/zZzWw/

標記

<div class="card"> 
    <div>Some Text brah</div> 
    <img src="http://www.zombiegames.net/inc/images/Flaming-Zombooka-2.gif"/> 
</div> 

CSS

/* I set width and height to the same as the image */ 
.card{ 
    width: 70px; 
    height: 70px; 
} 

.card div{ 
    display:none; 
} 

JS

$(function(){ 
    $('.card').click(function(){ 
     $(this).children('div').toggle(); 
     $(this).children('img').toggle(); 
    }); 
}); 

只能在用容器元素包裝的2個元素之間切換。

+0

啊..優雅。我知道在我開始瘋狂之前,我最好問問他。 – 2011-02-12 03:13:01

1

嘗試常規CSS。將圖像放在div中,並且具有可見性:隱藏。使用JavaScript切換到可見性:可見。也許設置z-index。

1

使用CSS填充div,原始圖像爲背景。

然後更改CSS以獲得新的背景圖像。