欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 動(dòng)態(tài)數(shù)據(jù)下的錨點(diǎn)錯(cuò)位問(wèn)題解決方法

 更新時(shí)間:2008年12月24日 23:22:20   作者:  
用 Javascript 實(shí)現(xiàn)錨點(diǎn)(Anchor)間平滑跳轉(zhuǎn)
復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>用 Javascript 實(shí)現(xiàn)錨點(diǎn)(Anchor)間平滑跳轉(zhuǎn)</title>
  <script language="javascript">
  // 說(shuō)明 :用 Javascript 實(shí)現(xiàn)錨點(diǎn)(Anchor)間平滑跳轉(zhuǎn)
  
  // 轉(zhuǎn)換為數(shù)字
  function intval(v)
  {  
  v = parseInt(v);  
  return isNaN(v) ? 0 : v;
  } 
  // 獲取元素信息
  function getPos(e)
  {  
  var l = 0;  
  var t = 0;  
  var w = intval(e.style.width);  
  var h = intval(e.style.height);  
  var wb = e.offsetWidth;  
  var hb = e.offsetHeight;  
  while (e.offsetParent)
  {    
   l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);    
   t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);    
   e = e.offsetParent;  
   }  
   l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0);  
   t += e.offsetTop + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0);  
   return {x:l, y:t, w:w, h:h, wb:wb, hb:hb}; } 
   // 獲取滾動(dòng)條信息
   function getScroll() 
   {  
   var t, l, w, h;     
   if (document.documentElement && document.documentElement.scrollTop)
   {    
   t = document.documentElement.scrollTop;    
   l = document.documentElement.scrollLeft;    
   w = document.documentElement.scrollWidth;    
   h = document.documentElement.scrollHeight;  
   }
   else if (document.body)
   {    
   t = document.body.scrollTop;    
   l = document.body.scrollLeft;    
   w = document.body.scrollWidth;    
   h = document.body.scrollHeight;  
   }  
   return { t: t, l: l, w: w, h: h };
   } 
   // 錨點(diǎn)(Anchor)間平滑跳轉(zhuǎn)
   function scroller(el, duration)
   {  
   if(typeof el != 'object')
   {
   el = document.getElementById(el);
   }   
   if(!el) return;   
   var z = this;  
   z.el = el;  
   z.p = getPos(el);  
   z.s = getScroll();  
   z.clear = function()
   {
   window.clearInterval(z.timer);z.timer=null
   };  
   z.t=(new Date).getTime();   
   z.step = function()
   {    
   var t = (new Date).getTime();    
   var p = (t - z.t) / duration;    
   if (t >= duration + z.t)
   {      
   z.clear();      
   window.setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);     }
   else {      
   st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;      
   sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;      
   z.scroll(st, sl);    
   }  
   };  
   z.scroll = function (t, l){window.scrollTo(l, t-20)};  
   z.timer = window.setInterval(function(){z.step();},13);
   }
  </script>
  <style type="text/css">
  div.test
  {  
  width:400px;   margin:5px auto;   border:1px solid #ccc;
  }
  div.test strong
  {   font-size:16px;   background:#fff;   border-bottom:1px solid #aaa;   margin:0;   display:block;   padding:5px 0;   text-decoration:underline;   color:#059B9A;   cursor:pointer; } div.test p {   height:400px;   background:#f1f1f1;   margin:0;
  }
   </style>
</head>
<body>
  <form id="form1" runat="server">
  <div class="test">  
  <a name="header_1" id="header_1"></a>  
  <strong onclick="javascript:scroller('header_4', 800);">header_1 --> header_4</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_2" id="header_2"></a>  
  <strong onclick="javascript:scroller('header_5', 800);">header_2 --> header_5</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_3" id="header_3"></a>  
  <strong onclick="javascript:scroller('header_6', 800);">header_3 --> header_6</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_4" id="header_4"></a>  
  <strong onclick="javascript:scroller('header_7', 800);">header_4 --> header_7</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_5" id="header_5"></a>  
  <strong onclick="javascript:scroller('header_3', 800);">header_5 --> header_3</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_6" id="header_6"></a>  
  <strong onclick="javascript:scroller('header_2', 800);">header_6 --> header_2</strong><p></p>
  </div> 
  <div class="test">  
  <a name="header_7" id="header_7"></a>  
  <strong onclick="javascript:scroller('header_1', 800);">header_7 --> header_1</strong><p></p>
  </div>
  </form>
</body>
</html>
  • 利用javascript如何隨機(jī)生成一定位數(shù)的密碼

    利用javascript如何隨機(jī)生成一定位數(shù)的密碼

    這篇文章主要給大家介紹了關(guān)于利用javascript如何隨機(jī)生成一定位數(shù)的密碼的相關(guān)資料,文中給出了詳細(xì)的示例代碼,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-09-09
  • 微信小程序?qū)崿F(xiàn)上傳word、txt、Excel、PPT等文件功能

    微信小程序?qū)崿F(xiàn)上傳word、txt、Excel、PPT等文件功能

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)上傳word、txt、Excel、PPT等文件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • js和jquery中獲取非行間樣式

    js和jquery中獲取非行間樣式

    本篇文章主要介紹了js和jquery中獲取非行間樣式的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧
    2017-05-05
  • JavaScript常用截取字符串的三種方式用法區(qū)別實(shí)例解析

    JavaScript常用截取字符串的三種方式用法區(qū)別實(shí)例解析

    本文給大家分享JavaScript常用截取字符串的三種方式及每種用法的區(qū)別解析,感興趣的朋友跟隨腳本之家小編一起看看吧
    2018-05-05
  • JavaScript將取代AppleScript?

    JavaScript將取代AppleScript?

    這篇文章主要介紹了JavaScript將取代AppleScript?AppleScript是OS X平臺(tái)的類(lèi)似JavaScript的腳本語(yǔ)言,需要的朋友可以參考下
    2014-09-09
  • 全面解析Bootstrap中tab(選項(xiàng)卡)的使用方法

    全面解析Bootstrap中tab(選項(xiàng)卡)的使用方法

    這篇文章主要為大家全面解析Bootstrap中tab(選項(xiàng)卡)的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • FF和IE之間7個(gè)JavaScript的差異

    FF和IE之間7個(gè)JavaScript的差異

    盡管 JavaScript 歷史上使用冗長(zhǎng)而令人生厭的代碼塊來(lái)標(biāo)的特定瀏覽器的時(shí)期已經(jīng)結(jié)束了,但是偶爾使用一些簡(jiǎn)單的代碼塊和對(duì)象檢測(cè)來(lái)確保一些代碼在用戶機(jī)器上正常工作依然是必要的。
    2009-05-05
  • javascript封裝 Cookie 應(yīng)用接口

    javascript封裝 Cookie 應(yīng)用接口

    本文通過(guò)幾個(gè)簡(jiǎn)單的示例向大家展示了javascript封裝cookie的注意事項(xiàng)及操作方法,非常的簡(jiǎn)單實(shí)用,最后附上一則具體實(shí)例,有需要的小火把可以參考下。
    2015-08-08
  • Javascript實(shí)現(xiàn)找不同色塊的游戲

    Javascript實(shí)現(xiàn)找不同色塊的游戲

    先給大家說(shuō)下游戲規(guī)則:在變化數(shù)量的顏色塊里找出一個(gè)不同顏色的塊點(diǎn)擊。下面通過(guò)js代碼給大家分享找不同色塊的游戲?qū)崿F(xiàn)方法,需要的朋友參考下吧
    2017-07-07
  • 最新評(píng)論