2013-11-21 3 views
0

jQuery noConflict에 문제가 있습니다. jQuery를 넣으려고하는 페이지에는 이미 noConflict() 규칙을 사용하는 드롭 다운 탐색 기능이 있습니다. 다른 애니메이션에 대해 한 페이지에 noConlfict를 두 개 이상 사용할 수 있습니까? 한 페이지에 3 개의 다른 jQuery 함수가 동시에 실행됩니다. 별도로 그들은 잘 작동하지만 한 번 페이지에 추가하면 작업을 멈 춥니 다. 아래는 실행해야하는 jQuery 중 하나입니다. 누군가가 noConflict() 규칙을 추가하도록 도울 수 있습니까?jQuery가 한 페이지의 다른 페이지와 충돌합니다.

$(function() { 
var current = 1; 


var iterate = function(){ 
    var i = parseInt(current+1); 
    var lis = $('#rotmenu').children('li').size(); 
    if(i>lis) i = 1; 
    display($('#rotmenu li:nth-child('+i+')')); 
} 
display($('#rotmenu li:first')); 
var slidetime = setInterval(iterate,5000); 

$('#rotmenu li').bind('click',function(e){ 
    clearTimeout(slidetime); 
    display($(this)); 
    e.preventDefault(); 
}); 

function display(elem){ 
    var $this = elem; 
    var repeat = false; 
    if(current == parseInt($this.index() + 1)) 
     repeat = true; 

    if(!repeat) 
     $this.parent().find('li:nth-child('+current+') a').stop(true,true).animate({'marginRight':'-20px'},300,function(){ 
      $(this).animate({'opacity':'0.7'},700); 
     }); 

    current = parseInt($this.index() + 1); 

    var elem = $('a',$this); 

     elem.stop(true,true).animate({'marginRight':'0px','opacity':'1.0'},300); 

    var info_elem = elem.next(); 
    $('#rot1 .heading').animate({'left':'-420px'}, 500,'easeOutCirc',function(){ 
     $('h1',$(this)).html(info_elem.find('.info_heading').html()); 
     $(this).animate({'left':'0px'},400,'easeInOutQuad'); 
    }); 

    $('#rot1 .description').animate({'bottom':'-270px'},500,'easeOutCirc',function(){ 
     $('p',$(this)).html(info_elem.find('.info_description').html()); 
     $(this).animate({'bottom':'0px'},400,'easeInOutQuad'); 
    }) 
    $('#rot1').prepend(
    $('<img/>',{ 
     style : 'opacity:0', 
     className : 'bg' 
    }).load(
    function(){ 
     $(this).animate({'opacity':'1'},600); 
     $('#rot1 img:first').next().animate({'opacity':'0'},700,function(){ 
      $(this).remove(); 
     }); 
    } 
).attr('src', info_elem.find('.info_image').html()) 
); 
} 

}); @adaneo 이미 주석으로

+4

코드를 래핑하기 위해'jQuery (function ($) {...});'를 사용하십시오. 대신 – adeneo

+3

위젯 당 하나가 아닌 ** 하나 ** 버전의 jQuery를 포함해야합니다. – Pointy

+0

@Pointy 모든 위젯이 동일한 버전의 jQuery를 호출하면 어떨까요? – user3015352

답변

0

, 당신은 항상 jQuery를 방법으로 당신의 코드를 포장해야하지만, 그 후 당신은 첫 번째 매개 변수 진정한와 noConflict를 호출해야합니다 : 이것은에서 완전히 jQuery를 제거

$.noConflict(true); 

jQuery 및 $ variable을 호출하고 jQuery 객체를 반환합니다. 이 반환 값을 매개 변수로 객체 나 메소드에 부여하여 코드에서 사용할 수 있습니다.

function MyFunction($) { 
    $(doSomeThing); 
} 
MyFunction($.noConflict(true)); 
관련 문제