任何人都可以帮助我如何处理这2个javascript冲突

时间:2009-08-25 07:42:28

标签: javascript ajax conflict

第一个脚本,允许我创建一个移动的云,并在到达结束后循环


// dvdp - volll - iphone alert

var agent=navigator.userAgent.toLowerCase();
var is_iphone = (agent.indexOf('iphone')!=-1);


//  TJP - volll

var stispace=new Array();
var jumpspace=new Array();
var skyspace=new Array; skyspace['dir']=-1; skyspace['place']=0;
var smokespace=0;
var shipspace=0;
var cloudspace=new Array();
var stagespace=2000;

cloudspace[1]=new Array(); cloudspace[1]['w']=219; cloudspace[1]['p']=2000;
cloudspace[2]=new Array(); cloudspace[2]['w']=128; cloudspace[2]['p']=1050;
cloudspace[3]=new Array(); cloudspace[3]['w']=51; cloudspace[3]['p']=1200;
cloudspace[4]=new Array(); cloudspace[4]['w']=112; cloudspace[4]['p']=120;
cloudspace[5]=new Array(); cloudspace[5]['w']=219; cloudspace[5]['p']=130;
cloudspace[6]=new Array(); cloudspace[6]['w']=219; cloudspace[6]['p']=1020;
cloudspace[7]=new Array(); cloudspace[7]['w']=219; cloudspace[7]['p']=1400;

var movespace='';
var scrollspace=0;

function $(id) {
 return document.getElementById(id);
}

function smoothto(whereto) {
wheretoreal=whereto;
 if(scrollspace == 1) {return false;}
 if(whereto == 'section_about_who') { whereto='section_about';}
 if(whereto == 'section_about_contact') { whereto='section_about';}
 scrollspace=1;
 wheretoscroll=0;
 wherefromscroll=topget();
 for(smt=0;smt<pag_sections_name.length;smt++) {
  if(smt>0) {wheretoscroll+=pag_sections_height[smt-1]}
  if(pag_sections_name[smt] == whereto) {smt=pag_sections_name.length;}
 }
 if(wherefromscroll==wheretoscroll) {
  scrollspace=0;
  window.location='#'+wheretoreal;
  return false;
 }else{
     window.paused=1;
    clearInterval(int_TJPfloat);
    clearInterval(int_TJProllsky);
 }

 $('vollltv').style.height='0';
 tmp=new Array();
 steps=20;
 for(smt=1;smt<=steps;smt++) {
  pt=smt/steps;
  if(pt == .5) {
   multi=1.5
  } else {
   multi=(Math.sqrt(Math.abs(2*pt-1))*(2*pt-1)/Math.abs(2*pt-1)+1)/2;
  }
  multi=Math.sqrt(smt/steps);
  tmp[smt]='window.scroll(0,'+(wherefromscroll+(wheretoscroll-wherefromscroll)*multi)+');';
 }
 tmp[steps]+="window.location='#"+wheretoreal+"';$('vollltv').style.height='278px'; scrollspace=0;";
  tmp[steps]+=" window.int_TJProllsky=undefined; window.int_TJProllsky=setInterval('TJProllsky();',200);";
tmp[steps]+="window.int_TJPfloat=undefined; window.int_TJPfloat=setInterval('TJPfloat();',50);";
tmp[steps]+="window.paused=0; ";
 //alert(tmp.join("\n"));
 ttt=Math.random();
 stispace[ttt]=tmp;
 setTI(ttt,10);
 return false;
}


function volllresize() {
  d=document.body.clientWidth;
  if(d && d>1000) {
    stagespace=d;
  }
  if($('inter4')) {
   if (self.innerHeight) {
    ch = self.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientHeight) {
    ch = document.documentElement.clientHeight;
   }
   else if (document.body) {
    ch = document.body.clientHeight;
   }
   if(ch>600) {
    $('inter4').style.height=(ch-534)+'px';
   }
  }
}

function volllinit(section) {
 if(section == 'inter0' && !is_iphone) {

  volllresize();
  window.onresize=volllresize;
  for(i=1;i<cloudspace.length;i++) {
   cloudspace[i]['p']*=d/1000;
  }
  //if(tmp.split('#')[1] == '' || tmp.split('#')[1] == 'section_main') {
  // setTimeout('scroll(0,200);',100);
  //}
 }
 else if(section == 'about') {
  window.int_TJPfloat=setInterval("TJPfloat();",50);
  tmp=location.href+'#'; 
 }
}
window.paused=0;

        function TJPmovecloud(cid,pos) {
         if(pos > stagespace && window.paused>0 ) {
          return;
         }
         if(pos+cloudspace[cid]['w']>stagespace) {
          $('s_cloud'+cid).style.width=stagespace-pos+'px';
         } else {
          $('s_cloud'+cid).style.width=cloudspace[cid]['w']+'px';
         }
         $('s_cloud'+cid).style.left=pos+'px';

}


function TJPfloat() {
 sy=Math.floor(Math.sin(smokespace)*20+20);
 sy2=Math.floor(Math.sin(smokespace)*10+10);
 sx=Math.floor(Math.cos(smokespace)*3+3);
 //if(smokespace==0) {alert('about.css-be belerakni:'+sy+'px 0 0 '+sx+'px');}
 $('g_wave1').style.margin=sy+'px 0 0 '+sy+'px';
 $('g_wave2').style.margin=sy2+'px 0 0 '+sy2+'px';
 smokespace+=.05; if(smokespace>2*Math.PI) {smokespace-=2*Math.PI;}
 if($('inter1')) {
  for(i=1;i<cloudspace.length;i++) {
   if(cloudspace[i]['p'] >= stagespace) {cloudspace[i]['p']=-cloudspace[i]['w'];}
   else if(cloudspace[i]['p'] <= -cloudspace[i]['w']) {cloudspace[i]['p']=stagespace;}
   cloudspace[i]['p']-=1+cloudspace[i]['w']/200;
   TJPmovecloud(i,cloudspace[i]['p']);
  }
 }
}

第二个脚本是创建弹跳效果的脚本,如tim van damme


<script type="text/javascript" charset="utf-8">

  $('.navigation').each(function () {
    var $links = $(this).find('a'),
      panelIds = $links.map(function() { return this.hash; }).get().join(","),
      $panels = $(panelIds),
      $panelwrapper = $panels.filter(':first').parent(),
      delay = 500,
      heightOffset = 40; // we could add margin-top + margin-bottom + padding-top + padding-bottom of $panelwrapper

    $panels.hide();

    $links.click(function () {
      var link = this, 
        $link = $(this);

      // ignore if already visible
      if ($link.is('.selected')) {
        return false;
      }

      $links.removeClass('selected');
      $link.addClass('selected');

      document.title = 'jQuery look: Tim Van Damme - ' + $link.text();

      if ($.support.opacity) {
        $panels.stop().animate({opacity: 0 }, delay);
      }

      $panelwrapper.stop().animate({
        height: 0
      }, delay, function () {
        var height = $panels.hide().filter(link.hash).css('opacity', 1).show().height() + heightOffset;

        $panelwrapper.animate({
          height: height
        }, delay);
      });
    });

    $links.filter(window.location.hash ? '[hash=' + window.location.hash + ']' : ':first').click();
  });
</script>

这是我收到的错误

TypeError:表达式'$('。navigation')的结果'[null]不是对象。任何人都可以向我解释为什么会出现这种错误吗?

2 个答案:

答案 0 :(得分:1)

您收到此错误,因为如果第一个代码中包含以下函数:

function $(id) {
 return document.getElementById(id);
}

这与第二段代码所需的jQuery的$函数重叠。重写第一段代码以使用jQuery的$()函数或在第一段代码中重命名$()并查找/替换。

答案 1 :(得分:0)

您的代码中是否有类名为“navigation”的html元素?