繁体   English   中英

为什么我的jQuery无法与1.9.1版一起使用?

[英]Why won't my jQuery work with version 1.9.1?

因此,基本上我的整个网站都可以使用jQuery 1.9.1版。 虽然,我想使用仅使用1.4.1版的插件。 为了与1.9.1兼容,此插件代码中是否必须更改一些小的内容?

我尝试了一些操作,例如将其转换为纯Javascript(没有运气)并尝试加载1.4.1 aswel版本。尽管这仅导致我网站上的许多其他内容也无法正常工作。

$(document).ready(function () {

        // Get all the thumbnail
        $('div.thumbnail-item').mouseenter(function(e) {

            // Calculate the position of the image tooltip
            x = e.pageX - $(this).offset().left;
            y = e.pageY - $(this).offset().top;

            // Set the z-index of the current item, 
            // make sure it's greater than the rest of thumbnail items
            // Set the position and display the image tooltip
            $(this).css('z-index','15')
            .children("div.tooltip")
            .css({'top': y + 10,'left': x + 20,'display':'block'});

        }).mousemove(function(e) {

            // Calculate the position of the image tooltip          
            x = e.pageX - $(this).offset().left;
            y = e.pageY - $(this).offset().top;

            // This line causes the tooltip will follow the mouse pointer
            $(this).children("div.tooltip").css({'top': y + 10,'left': x + 20});

        }).mouseleave(function() {

            // Reset the z-index and hide the image tooltip 
            $(this).css('z-index','1')
            .children("div.tooltip")
            .animate({"opacity": "hide"}, "fast");
        });

    });

这些是我收到的错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://jqueryui.com/slider/jquery-ui.js
Uncaught ReferenceError: jq141 is not defined (index):574
2999 (index):660
Failed to load resource: the server responded with a status of 404 (Not Found) http://www.ozcaravan-sales.com.au/wp-content/themes/listings/style/images/ui-bg_glass_75_e6e6e6_1x400.png
Failed to load resource: the server responded with a status of 404 (Not Found) http://www.ozcaravan-sales.com.au/wp-content/themes/listings/style/images/ui-bg_flat_75_ffffff_40x100.png
Failed to load resource: the server responded with a status of 404 (Not Found) http://www.ozcaravan-sales.com.au/wp-content/themes/listings/style/images/ui-bg_highlight-soft_75_cccccc_1x100.png
Failed to load resource: the server responded with a status of 404 (Not Found) http://dev.wizie.com/team/http://mangocell/favicon.ico
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

在每个jQuery版本中,不推荐使用某些api方法并将其删除,并添加了其他一些方法。 我认为您的插件正在尝试访问jQuery核心中某些已删除的方法。 对于解决方案,您可以找到插件的新版本(如果已维护)或找到具有相同功能的新插件。 您也可以使用jQuery migration插件,但是它仅支持等于或大于jQuery 1.6.4的版本。 在这里查看更多信息

好的,所以在调查之后,我在1.9.1中尝试了该插件,并且效果很好。 我没有任何错误。 如果您的示例不起作用,我认为1.9.1不是您的问题。
http://jsfiddle.net/NLw5F/

那就是在jQuery 1.9.1中工作的插件。

    $(document).ready(function () {

    // Get all the thumbnail
    $('div.thumbnail-item').mouseenter(function(e) {

        // Calculate the position of the image tooltip
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;

        // Set the z-index of the current item, 
        // make sure it's greater than the rest of thumbnail items
        // Set the position and display the image tooltip
        $(this).css('z-index','15')
        .children("div.tooltip")
        .css({'top': y + 10,'left': x + 20,'display':'block'});

    }).mousemove(function(e) {

        // Calculate the position of the image tooltip          
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;

        // This line causes the tooltip will follow the mouse pointer
        $(this).children("div.tooltip").css({'top': y + 10,'left': x + 20});

    }).mouseleave(function() {

        // Reset the z-index and hide the image tooltip 
        $(this).css('z-index','1')
        .children("div.tooltip")
        .animate({"opacity": "hide"}, "fast");
    });

});

直接来自演示。

暂无
暂无

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

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