我有一個圖像,我想淡出在標題div。當鼠標進入div時,caption div應該直接淡入圖像,鼠標離開時淡入淡出。mouseenter /離開img淡入/淡出文本div不工作
其次,我想添加一個click toggleClass函數來選擇和取消選擇圖像。當選擇圖像時,標題應該保持顯示/顯示。當通過點擊取消選擇圖像時,標題應該爲fadeOut。
底線:1)鼠標輸入/退出淡入/淡出標題2)點擊切換選擇類以保持標題顯示或取消選擇隱藏。
的FiddleJS:http://jsfiddle.net/jhyqt5/cBsqN/
HTML:
<div class="caption">Into the Night</div>
<img src="https://scontent-a-pao.xx.fbcdn.net/hphotos-frc1/189612_10100244250167513_7332862_n.jpg" class="img-circle">
</div>
CSS:
.img-circle{
border-radius: 50%; height: 140px; width: 140px;
}
.caption{
background-color: black; opacity: .7;
text-align: center; line-height: 120px; color: white;
position: absolute; display: none;
border-radius: 50%; height: 140px; width: 140px;
}
JS:
$('.caption').mouseenter(function(){
var image = $(this).find('img'),
caption = $(this).find('div');
caption.height(image.height());
caption.width(image.width());
caption.fadeIn();
}).mouseleave(function(){
var image = $(this).find('img'),
caption = $(this).find('div');
caption.height(image.height());
caption.width(image.width());
caption.fadeOut();
});
這太棒了!感謝演示。我實際上剛剛開始編碼一個星期前,當說「把jquery添加到你的小提琴」時它意味着什麼?我發送的小提琴鏈接實際上也是我的第一次嘗試,請解釋一下。謝謝 – DHuang
@HanJunQing歡迎您...歡迎來到Stack Overflow !!! :) – PSL