2013-03-03 31 views
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> 
+0

我不知道的行'宽度= $(” zitem,.take2。 ')宽()*变焦;'和'高度= $('。 zitem,.take2')。height()* zoom;'。您应该使用'$(this)'来代替。 – varnie 2013-03-03 09:19:49

回答

1

尝试

var width = $(this).width() * zoom; 
etc. 
+0

这没有效果。 – London804 2013-03-03 09:43:41