js實現(xiàn)緩動動畫
本文實例為大家分享了js實現(xiàn)緩動動畫的具體代碼,供大家參考,具體內(nèi)容如下

利用定時器來控制元素的offsetLeft的值,offsetLeft = 開始位置 + (最終位置 - 開始位置)* 緩動系數(shù)
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style> * { margin: 0; padding: 0; border: none; list-style: none; } body { background-color: pink; } #nav { width: 900px; height: 63px; background: url('images/doubleOne.png') no-repeat right center #fff; margin: 0 auto; margin-top: 50px; border-radius: 5px; position: relative; } #nav ul { line-height: 70px; } #nav ul li { float: left; height: 63px; width: 88px; text-align: center; cursor: pointer; position: relative; } #t_mail { width: 88px; height: 63px; background: url('images/tMall.png') no-repeat; position: absolute; } </style></head><body> <nav id='nav'> <span id='t_mail'></span> <ul> <li>雙11狂歡</li> <li>服裝會場</li> <li>數(shù)碼家電</li> <li>母嬰童裝</li> <li>手機會場</li> <li>美妝會場</li> <li>家居建材</li> <li>進(jìn)口會場</li> <li>飛豬旅行</li> </ul> </nav> <script> window.onload = function () { var nav = $(’nav’); var t_mall = nav.children[0]; var ul = nav.children[1]; var allLis = ul.children; var beginX = 0; for (var i = 0; i < allLis.length; i++) { var li = allLis[i]; li.onmouseover = function () { end = this.offsetLeft; } li.onmousedown = function () { beginX = this.offsetLeft; } li.onmouseout = function () { end = beginX; } } var begin = 0, end = 0; setInterval(function () { begin = begin + (end - begin) / 10; t_mall.style.left = begin + ’px’; }, 10) function $(id) { return typeof id ? document.getElementById(id) : null; } } </script></body></html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. IntelliJ IDEA設(shè)置自動提示功能快捷鍵的方法2. PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(二)3. Python3 json模塊之編碼解碼方法講解4. ASP.NET MVC使用jQuery ui的progressbar實現(xiàn)進(jìn)度條5. PHP如何開啟Opcache功能提升程序處理效率6. 從Python的字符串中剝離所有非數(shù)字字符(“。”除外)7. JavaScript創(chuàng)建表格的方法8. python新手學(xué)習(xí)使用庫9. android H5本地緩存加載優(yōu)化的實戰(zhàn)10. 詳解如何使用Net將HTML簡歷導(dǎo)出為PDF格式

網(wǎng)公網(wǎng)安備