user1002272
user1002272

Reputation:

jquery works only in single div

I tried to implement the Hover effect for images just like Google Images in my site http://windows7themer.com but its working only in the first div section.

That page has around 5 repeated div sections. And also I want to resize the image to variable size as in google images.

Here is the original jsfiddle : http://jsfiddle.net/roXon/HmTrw/

// ibox image zoomer plugin // roXon

(function($) {
    $.fn.ibox = function() {

        // set zoom ratio //
        resize = 20;
        ////////////////////
        var img = this;
        img.parent().append('<div id="ibox" />');
        var ibox = $('#ibox');
        var elX = 0;
        var elY = 0;

        img.each(function() {
            var el = $(this);

            el.mouseenter(function() {
                ibox.html('');
                var elH = el.height();
                elX = el.position().left - 6; // 6 = CSS#ibox padding+border
                elY = el.position().top - 6;
                var h = el.height();
                var w = el.width();
                var wh;
                checkwh = (h < w) ? (wh = (w / h * resize) / 2) : (wh = (w * resize / h) / 2);

                $(this).clone().prependTo(ibox);
                ibox.css({
                    top: elY + 'px',
                    left: elX + 'px'
                });

                ibox.stop().fadeTo(200, 1, function() {
                    $(this).animate({top: '-='+(resize/2), left:'-='+wh},400).children('img').animate({height:'+='+resize},400);
                });
            });

            ibox.mouseleave(function() {
                ibox.html('').hide();
            });
        });
    };
})(jQuery);

jQuery(document).ready(function() {
    jquery('.item').ibox();
});

please guide me in this.

Upvotes: 0

Views: 235

Answers (1)

Julien Bourdon
Julien Bourdon

Reputation: 1723

I checked your website and the problem comes from your CSS:

media="all"
.grid-view, .list-view {
position: relative;
display: inline-block;
float: left;
clear: both;
width: 100%;
}

you should delete position: relative; and it will work.

Also try to replace

$(this).animate({top: '-='+(resize/2), left:'-='+wh},400).children('img').animate({height:'+='+resize},400)

by

$(this).animate({top: '-='+(resize/2), left:'-='+wh},400).find('img').animate({height:'+='+resize},400)

Upvotes: 1

Related Questions