(42) JS motion multi-object framework-widening multiple div

Source: Internet
Author: User

(42) JS motion multi-object framework-widening multiple div

If only one timer is added for the div, a problem occurs when multiple divs become wide. However, if you add a timer for each div, you can increase the width of multiple objects. Note: When multiple objects are moving, nothing can be shared. OffsetXXX conflicts with border and thus cannot obtain desired results. Here, you can use the getStyle () function instead.

function getStyle(obj, name){if(obj.currentStyle){return obj.currentStyle[name];}else{return getComputedStyle(obj, false)[name];}}

  <script>window.onload=function (){var aDiv=document.getElementsByTagName('div');for(var i=0;iseover=function (){startMove(this,400);};aDiv[i].onmouseout=function (){startMove(this,100);};}};var timer=null;function startMove(obj, iTarget){clearInterval(obj.timer);obj.timer=setInterval(function (){var speed=(iTarget-obj.offsetWidth)/6;speed=speed>0?Math.ceil(speed):Math.floor(speed);if(obj.offsetWidth==iTarget){clearInterval(obj.timer);}else{obj.style.width=obj.offsetWidth+speed+'px';}}, 30);}</script>                     
:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.