0

我尝试在我的网站http://windows7themer.com中为图像实现悬停效果,就像 Google 图片一样,但它只在第一个 div 部分有效。

该页面有大约 5 个重复的 div 部分。而且我想将图像调整为可变大小,就像在谷歌图像中一样。

这是原始的 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();
});

请指导我。

4

1 回答 1

1

我检查了您的网站,问题来自您的 CSS:

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

你应该删除position: relative;它,它会起作用。

也尝试更换

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

经过

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

于 2012-06-26T16:44:16.027 回答