jquery菜单与其他脚本冲突

时间:2015-02-16 09:50:43

标签: javascript jquery

我正在使用“responsivemobilemenu.com”它的工作正常但在我在我的页面上使用下面的脚本后,responsivemobilemenu停止工作, 所以我认为脚本与jquery冲突,我试图解决这个问题,但没有做到正确:(。

js代码:

 var Class={create:function(){return function(){this.initialize.apply(this,arguments)}}};Object.extend=function(a,c){for(var b in c){a[b]=c[b]}return a};Function.prototype.bind=function(b){var a=this;return function(){return a.apply(b,arguments)}};if(!Array.prototype.forEach){Array.prototype.forEach=function(b,c){for(var a=0;a<this.length;a++){b.call(c,this[a],a)}}}Array.prototype.each=Array.prototype.forEach;String.prototype.camelize=function(){return this.replace(/-\D/gi,function(a){return a.charAt(a.length-1).toUpperCase()})};var $A=function(c){var b=[];for(var a=0;a<c.length;a++){b.push(c[a])}return b};function $(){if(arguments.length==1){return b(arguments[0])}var a=[];$c(arguments).each(function(c){a.push(b(c))});return a;function b(c){if(typeof c=="string"){c=document.getElementById(c)}return c}}if(!window.Element){var Element={}}Object.extend(Element,{remove:function(a){a=$(a);a.parentNode.removeChild(a)},hasClassName:function(a,b){a=$(a);return !!a.className.match(new RegExp("\\b"+b+"\\b"))},addClassName:function(a,b){a=$(a);if(!Element.hasClassName(a,b)){a.className=(a.className+" "+b)}},removeClassName:function(a,b){a=$(a);if(Element.hasClassName(a,b)){a.className=a.className.replace(b,"")}}});document.getElementsByClassName=function(b){var c=[];var Date().getTime();this.timer=setInterval(this.step.bind(this),Math.round(1000/this.options.fps));return this},custom:function(b,a){return this._start(b,a)},set:function(a){this.now=a;this.increase();return this},hide:functhis.property=c.camelize()},increase:function(){this.setStyle(this.element,this.property,this.now)}});Fx.Styles=Class.create();Fx.Styles.prototype=Object.extend(new Fx.Base(),{initialize:function(b,a){this.element=$(b);this.setOptions(a);this.now={}},setNow:function(){for(p in this.from){this.now[p]=this.compute(this.from[p],this.to[p])}},custom:function(a){if(this.timer&&this.options.wait){return}var c={};var b={};for(p in a){c[p]=a[p][0];b[p]=a[p][1]}return this._start(c,b)},increase:function(){for(var a in this.now){this.setStyle(this.element,a,this.now[a])}}});Fx.Transitions={linear:function(e,a,g,f){return g*e/f+a},sineInOut:function(e,a,g,f){return -g/2*(Math.cos(Math.PI*e/f)-1)+a}};Fx.Accordion=Class.create();Fx.Accordion.prototype=Object.extend(new Fx.Base(),{extendOptions:function(a){Object.extend(this.options,Object.extend({start:"open-first",fixedHeight:false,fixedWidth:false,alwaysHide:false,wait:false,onActive:function(){},onBackground:function(){},height:true,opacity:true,width:false},a||{}))},initialize:function(b,c,a){this.now={};this.elements=$A(c);this.togglers=$A(b);this.setOptions(a);this.extendOptions(a);this.previousClick="nan";this.togglers.each(function(e,d){if(e.onclick){e.prevClick=e.onclick}else{e.prevClick=function(){}}$(e).onclick=function(){e.prevClick();this.showThisHideOpen(d)}.bind(this)}.bind(this));this.h={};this.w={};this.o={};this.elements.each(function(e,d){this.now[d+1]={};e.style.height="0";e.style.overflow="hidden"}.bind(this));switch(this.options.start){case"first-open":this.elements[0].style.height=this.elements[0].scrollHeight+"px";break;case"open-first":this.showThisHideOpen(0);break}},setNow:function(){for(var b in this.from){var e=this.from[b];var d=this.to[b];var a=this.now[b]={};for(var c in e){a[c]=this.compute(e[c],d[c])}}},custom:function(a){if(this.timer&&this.options.wait){return}var h={};var g={};for(var b in a){var c=a[b];var f=h[b]={};var e=g[b]={};for(var d in c){f[d]=c[d][0];e[d]=c[d][1]}}return this._start(h,g)},hideThis:function(a){if(this.options.height){this.h={height:[this.elements[a].offsetHeight,0]}}if(this.options.width){this.w={width:[this.elements[a].offsetWidth,0]}}if(this.options.opacity){this.o={opacity:[this.now[a+1]["opacity"]||1,0]}}},showThis:function(a){if(this.options.height){this.h={height:[this.elements[a].offsetHeight,this.options.fixedHeight||this.elements[a].scrollHeight]}}if(this.options.width){this.w={width:[this.elements[a].offsetWidth,this.options.fixedWidth||this.elements[a].scrollWidth]}}if(this.options.opacity){this.o={opacity:[this.now[a+1]["opacity"]||0,1]}}},showThisHideOpen:function(d){if(d!=this.previousClick||this.options.alwaysHide){this.previousClick=d;var a={};var b=false;var c=false;this.elements.each(function(f,e){this.now[e]=this.now[e]||{};if(e!=d){this.hideThis(e)}else{if(this.options.alwaysHide){if(f.offsetHeight==f.scrollHeight){this.hideThis(e);c=true}else{if(f.offsetHeight==0){this.showThis(e)}else{b=true}}}else{if(this.options.wait&&this.timer){this.previousClick="nan";b=true}else{this.showThis(e)}}}a[e+1]=Object.extend(this.h,Object.extend(this.o,this.w))}.bind(this));if(b){return}if(!c){this.options.onActive.call(this,this.togglers[d],d)}this.togglers.each(function(f,e){if(e!=d||c){this.options.onBackground.call(this,f,e)}}.bind(this));return this.custom(a)}},increase:function(){for(var b in this.now){var a=this.now[b];for(var c in a){this.setStyle(this.elements[parseInt(b)-1],c,a[c])}}}});

我的页面:

 <body>
 <div >the responsivemobilemenu here</div>

 <script>the above script exist here</script>
 <script>var myAccordion;
 var myStretch;
 var myStretcher;
 window.onload = function() {
false, alwaysHide:true});
 myAccordion.showThisHideOpen(1000);
}</script>

2 个答案:

答案 0 :(得分:0)

如果删除

中的空白
myAccordion = new Fx. Accordion(myStretch, myStretche...

see this fiddle

答案 1 :(得分:0)

它似乎不是冲突,但你总是可以尝试使用它来找出: http://api.jquery.com/jquery.noconflict/

PS:请务必检查您的Javascript控制台是否有错误!