London804
London804

Reputation: 1126

How do I use jQuery to access more than one class

I am trying to use this jQuery function to make my image zoom as well as have a sliding text appear on hover. I want to use a total of 13 images that each have different dimensions. When I put more than one class in the jQuery function all the classes inherit the first class's css properties even though each image has it's own unique css properties. How do I design my function so that each class does not inherit the first class's css code?

<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>

Upvotes: 1

Views: 101

Answers (1)

thebjorn
thebjorn

Reputation: 27361

Try

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

Upvotes: 1

Related Questions