noClonflict() jQuery - No longer works

Asked

Viewed 178 times

2

Hello, I was using jQuery’s noClonflict() to not have conflict with the site http://www.casadoboteco.com.br/

Initially it worked, but after a few days is giving trouble again. It is giving conflict with the shop classes.

I have by no means succeeded in ending the clonflites among the classes.

I tried to change the $j to another name and it didn’t work.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript">/script>
<script>
var $j = jQuery.noConflict();
(function ($j) {
    $j(document).ready(function () {
        $j('#cssmenu').prepend('<div id="indicatorContainer"><div id="pIndicator"><div id="cIndicator"></div></div></div>');
        var activeElement = $j('#cssmenu>ul>li:first');

        $j('#cssmenu>ul>li').each(function () {
            if ($j(this).hasClass('active')) {
                activeElement = $j(this);
            }
        });

        var posLeft = activeElement.position().left;
        var elementWidth = activeElement.width();
        posLeft = posLeft + elementWidth / 2 - 6;
        if (activeElement.hasClass('has-sub')) {
            posLeft -= 6;
        }

        $j('#cssmenu #pIndicator').css('left', posLeft);
        var element, leftPos, indicator = $j('#cssmenu pIndicator');

        $j("#cssmenu>ul>li").hover(function () {
            element = $j(this);
            var w = element.width();
            if ($j(this).hasClass('has-sub')) {
                leftPos = element.position().left + w / 2 - 12;
            } else {
                leftPos = element.position().left + w / 2 - 6;
            }

            $j('#cssmenu #pIndicator').css('left', leftPos);
        }, function () {
            $j('#cssmenu #pIndicator').css('left', posLeft);
        });

        $j('#cssmenu>ul').prepend('<li id="menu-button"><a>Menu</a></li>');
        $j("#menu-button").click(function () {
            if ($j(this).parent().hasClass('open')) {
                $j(this).parent().removeClass('open');
            } else {
                $j(this).parent().addClass('open');
            }
        });
    });
})(jQuery);

</script>
  • There’s some special reason you’re wearing ( function( $j ) {###} )( jQuery ); ?

  • This is the menu code, so it’s not my fault. The problem really is with conflict, because the menu works correctly. What doesn’t work is the market.

  • You have another code on the page that uses the dollar ($)?

  • Hard to know, since the built-in store is not open source. I can only put Javascript and CSS HTML codes.

1 answer

1

Tries to pass the jQuery.noConflict() for your IIFE (and remove the var $j = jQuery.noConflict() of the overall scope):

<script>
(function ($j) {

    /* código ... */

})(jQuery.noConflict());

</script>
  • When there’s time I’ll test it to see if it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.