简体   繁体   English

jQuery的图像悬停效果错误

[英]Jquery Image hover effect Error

I checked this link of SO : Pop Images like Google Images 我检查了SO的此链接: 像Google Images这样的Pop Images

And tried to setup the image hover effect. 并尝试设置图像悬停效果。

Everything worked fine when i tested it in here 我在这里测试时一切正常

// 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);

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

But when i added it to my site, I get the following error 但是,当我将其添加到我的网站时,出现以下错误

Uncaught TypeError: Property '$' of object [object Window] is not a function
    $('.hovermore').ibox();

I guess its because of other jquery effects in the site. 我猜这是由于网站中其他jquery的影响。

Is there any way to solve this? 有什么办法解决这个问题?

尝试使用以下代码启动代码:

jQuery(document).ready(function ($) {

那是因为您忘记加载jQuery了:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>

Have you included jQuery on your page before calling $('.hovermore').ibox(); 在调用$('.hovermore').ibox();之前,您是否在页面上包含jQuery $('.hovermore').ibox(); ?

Also, I don't think it should matter, but also make sure you're using the latest version of jQuery. 另外,我认为这无关紧要,但还要确保您使用的是最新版本的jQuery。

Can you post a link to the page where it doesn't work so we can see all of the code? 您能否在无法正常工作的页面上发布链接,以便我们可以查看所有代码?

You forgot to include the jQuery library. 您忘记了包括jQuery库。

Visit this demo, go to SAVE -> DOWNLOAD and look at the downloaded file. 访问演示,转到“保存”->“下载”,然后查看下载的文件。

http://jsbin.com/ifefop/edit#javascript,html,live http://jsbin.com/ifefop/edit#javascript,html,live

Your document should have: 您的文件应包含:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

And if you placed the script in an external file: 并且如果您将脚本放置在外部文件中:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="js/ibox.js"></script>

Please try 请试试

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

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM