开发者

jquery noconflict()

I'm studying jquery yet. I read something about jquery noConflict as well, but everything I tried didn't work. I didn't understand how to use noConflict() and if is the right thing to do for my issue. I'm testing this project here.

Everything worked fine till when I put the autocomplete function. Now only the autocomplete search works, try searching for "et" in the input type, but here there is a problem that I don't understand: Uncaught TypeError: Cannot call method 'accordion' of null.

There is another problem with another function: "mostraparcelas" because is not defined at the moment, but doesn't change my problem if I delete the call to that function. I'm testing, so now there are some more problems with "mostraparcelas" but it isn't the real problem. I have problem with jquery corousel, JQUItabs, accordion, autocomplete and prototype working toghet开发者_开发知识库er.

I have just solved the first conflict with the accordion and noConflict like this:

    <script type="text/javascript"> 
<!--//--><![CDATA[//><!--
$.noConflict();
  jQuery(document).ready(function($) {
$("html").addClass("js");
$.fn.accordion.defaults.container = false; 
$(function() {
  $("#acc3").accordion({initShow : "#current"});
  $("#acc1").accordion({
      el: ".h", 
      head: "h4, h5", 
      next: "div", 
      initShow : "div.outer:eq(1)"
  });

   $("#acc2").accordion({
      obj: "div", 
      wrapper: "div", 
      el: ".h", 
      head: "h4, h5", 
      next: "div", 
      showMethod: "slideFadeDown",
      hideMethod: "slideFadeUp",
      initShow : "div.shown"
    });
  $("html").removeClass("js");
});
});
//--><!]]>
</script> 
<!--<![endif]--> 

I have the other problems yet. If this is easy for you try to help me instead degree my reputation.Thanks.


I have solved the others conflict too. For the carousel I used noConflict() in this way:

    <script type="text/javascript" charset="utf-8">
jQuery.noConflict();
(function($) { 
  $(function() { 
(function () {
    $.fn.infinitecarousel = function () {
        function repeat(str, n) {
            return new Array( n + 1 ).join(str);
        }
        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first')
                singleWidth = $single.outerWidth(true),
                visible = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = Math.ceil($items.length / visible);
            /* TASKS */
            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }
            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');
            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);
            // 4. paging function
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * visible * n;
                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft : '+=' + left
                }, 1000, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                     }
                    currentPage = page;
                });
            }
            // 5. insert the back and forward link
            $wrapper.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');
            // 6. bind the back and forward links
            $('a.back', this).click(function () {
                gotoPage(currentPage - 1);
                return false;
            });
            $('a.forward', this).click(function () {
                gotoPage(currentPage + 1);
                return false;
            });
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);

$(document).ready(function () {
    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = true;
    $('.infinitecarousel').infinitecarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    setInterval(function () {
        if (autoscrolling) {
            $('.infinitecarousel').trigger('next');
        }
    }, 6000);
});
});
})(jQuery);
</script> 

and for the tabs as the same above:

    <script type="text/javascript">
jQuery.noConflict();
(function($) { 
  $(function() {
    $(function() {
                                //Tabs
                        $( "#tabs" ).tabs();
    });
});
})(jQuery);
</script> 

Only for the accordion I have used noConflit() in a different way:

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

//script myAccordion.....

    });
});
//--><!]]>
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜