欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長(zhǎng)資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          javascript怎么實(shí)現(xiàn)不停淡入淡出

          實(shí)現(xiàn)方法:1、使用querySelector()獲取指定元素對(duì)象;2、使用“元素對(duì)象.style.opacity = Math.sin(2 * Math.PI * time)”語(yǔ)句來(lái)控制淡入或淡出效果;3、使用遞歸的方式實(shí)現(xiàn)不停淡入淡出。

          javascript怎么實(shí)現(xiàn)不停淡入淡出

          本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

          javascript實(shí)現(xiàn)不停淡入淡出

          只需要找到一個(gè)作用域?yàn)閇0,1]的周期函數(shù)。將周期函數(shù)的值作為opacity的屬性值即可控制淡入或淡出效果。

          利用遞歸即可不停淡入淡出。

          實(shí)現(xiàn)代碼:

          <h1 id="text">床前明月光,疑是地上霜。</h1> <script type="text/javascript"> var duration = 3000; var startTime = new Date(); var p = 0; requestAnimationFrame(function f(){   //獲取到元素   var el = document.querySelector("#text");    var time = ( new Date - startTime ) / duration;   el.style.opacity = Math.sin(2 * Math.PI * time);   requestAnimationFrame(f); });

          效果圖:

          javascript怎么實(shí)現(xiàn)不停淡入淡出

          【推薦學(xué)習(xí):javascript高級(jí)教程】

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)