1
我想使用此jQuery函數來使圖像縮放以及在懸停時顯示滑動文本。我想總共使用13個圖像,每個圖像都有不同的尺寸。當我在jQuery函數中放入多個類時,所有類都會繼承第一個類的css屬性,即使每個圖像都具有它自己的唯一css屬性。我如何設計我的功能,以便每個類不會繼承第一類的css代碼?如何使用jQuery訪問多個類
<script>
$(document).ready(function() {
//move the image in pixel
var move = -15;
//zoom percentage, 1.2 =120%
var zoom = 1.2;
//On mouse over those thumbnail
$('.zitem, .take2').hover(function() {
//Set the width and height according to the zoom percentage
width = $('.zitem, .take2').width() * zoom;
height = $('.zitem, .take2').height() * zoom;
//Move and zoom the image
$(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:1000});
//Display the caption
$(this).find('div.caption').stop(false,true).fadeIn(200);
},
function() {
//Reset the image
$(this).find('img').stop(false,true).animate({'width':$('.zitem, .take2').width(), 'height':$('.zitem, .take2').height(), 'top':'0', 'left':'0'}, {duration:500});
//Hide the caption
$(this).find('div.caption').stop(false,true).fadeOut(200);
});
});
</script>
我不知道的行'寬度= $(」 zitem,.take2。 ')寬()*變焦;'和'高度= $('。 zitem,.take2')。height()* zoom;'。您應該使用'$(this)'來代替。 – varnie 2013-03-03 09:19:49