好的,所以我有一个jQuery与MooTools一起使用一个脚本,将它添加到jQuery脚本的顶部:
var $j = jQuery.noConflict();
然后更换每个:
$(
同
$j(
但是你会如何让MooTools喜欢使用jQuery的以下脚本?
提前感谢任何投入,
特雷西
//Fade In Content Viewer: By JavaScript Kit: http://www.javascriptkit.com var fadecontentviewer={ csszindex: 100,fade:function($allcontents,togglerid,selected,speed){ var selected=parseInt(selected) var $togglerdiv=$("#"+togglerid) var $target=$allcontents.eq(selected) if ($target.length==0){ //if no content exists at this index position (ie: stemming from redundant pagination link) alert("No content exists at page number "+selected+"!") return } if ($togglerdiv.attr('lastselected')==null || parseInt($togglerdiv.attr('lastselected'))!=selected){ var $toc=$("#"+togglerid+" .toc") var $selectedlink=$toc.eq(selected) $("#"+togglerid+" .next").attr('nextpage',(selected<$allcontents.length-1)? selected+1+'pg' : 0+'pg') $("#"+togglerid+" .prev").attr('prevIoUspage',(selected==0)? $allcontents.length-1+'pg' : selected-1+'pg') $target.css({zIndex: this.csszindex++,visibility: 'visible'}) $target.hide() $target.fadeIn(speed) $toc.removeClass('selected') $selectedlink.addClass('selected') $togglerdiv.attr('lastselected',selected+'pg') } },setuptoggler:function($allcontents,speed){ var $toc=$("#"+togglerid+" .toc") $toc.each(function(index){ $(this).attr('pagenumber',index+'pg') }) var $next=$("#"+togglerid+" .next") var $prev=$("#"+togglerid+" .prev") $next.click(function(){ fadecontentviewer.fade($allcontents,$(this).attr('nextpage'),speed) return false }) $prev.click(function(){ fadecontentviewer.fade($allcontents,$(this).attr('prevIoUspage'),speed) return false }) $toc.click(function(){ fadecontentviewer.fade($allcontents,$(this).attr('pagenumber'),speed) return false }) },init:function(fadeid,contentclass,speed){ $(document).ready(function(){ var faderheight=$("#"+fadeid).height() var $fadecontents=$("#"+fadeid+" ."+contentclass) $fadecontents.css({top: 0,left: 0,height: faderheight,visibility: 'hidden'}) fadecontentviewer.setuptoggler($fadecontents,speed) setTimeout(function(){fadecontentviewer.fade($fadecontents,speed)},100) $(window).bind('unload',function(){ //clean up $("#"+togglerid+" .toc").unbind('click') $("#"+togglerid+" .next","#"+togglerid+" .prev").unbind('click') }) }) } }
解决方法
当你有使用$的jQuery特定代码时,最简单的方法是使用以下代码来包装代码:
// Disable the $ global alias completely jQuery.noConflict(); // For jQuery scripts (function($){ // set a local $ variable only available in this block as an alias to jQuery ... here is your jQuery specific code ... })(jQuery); // For Mootols scripts (function($){ // set a local $ variable only available in this block as an alias // to Mootools document.id ... here is your Mootools specific code ... })(document.id);
参见noConflict documentation的第二个例子。