2

これが私が使用しているスクリプトです。

$(window).load(function() {
$('#edifici, #artistici, #industriale, #fotovoltaico, #veterinaria, #architettonici').hide();

if (!!window.location.hash) {
    var hash = window.location.hash;
    var $content = $(hash);
    showContent($content)
}

$('.home').click(function () {
    var id = this.id.replace('mostra_', '');
    var $content = $('#' + id + ':not(:visible)');
    if ($('.current').length === 0) {
        showContent($content)
    } else {
        $('.current').fadeOut(600, function () {
            showContent($content)
        });
    }
});

function showContent(content) {
    content.fadeIn(600);
    $('.current').removeClass('current');
    content.addClass('current');
}
});

このガイドに従って、WordPress(非競合モードでjQueryを使用)で使用するために、スクリプトを次のように変更しました

jQuery.noConflict();

jQuery(window).load(function($) {
$('#edifici, #artistici, #industriale, #fotovoltaico, #veterinaria, #architettonici').hide();

if (!!window.location.hash) {
    var hash = window.location.hash;
    var $content = $(hash);
    showContent($content)
}

$('.home').click(function () {
    var id = this.id.replace('mostra_', '');
    var $content = $('#' + id + ':not(:visible)');
    if ($('.current').length === 0) {
        showContent($content)
    } else {
        $('.current').fadeOut(600, function () {
            showContent($content)
        });
    }
});

function showContent(content) {
    content.fadeIn(600);
    $('.current').removeClass('current');
    content.addClass('current');
}
});

残念ながら、正しく動作していないようです...何が間違っているのでしょうか?

4

1 に答える 1

6
jQuery.noConflict();

説明: jQuery による $ variable の制御を放棄します

これは、jQuery が $ を使用しなくなることを意味するため、他のライブラリとのすべての競合が解消されます。

$ を内部的に使用するには、次のようにします。

既存のコードを無名関数にラップし、jQuery を引数として渡すことができます。次に例を示します。

(function ($) {

    // use $ here
    $('#hello').html('world');

})(jQuery);

または、jQuery が提供するショートカットを使用します。

jQuery(function($) {

    // use $
    $('#hello').html('world');

});

ready メソッドも jQuery オブジェクトを渡します。

jQuery(document).ready(function ($) {
    // ...
});
于 2013-09-08T08:44:24.007 に答える