Javascript _ javascript tips

Source: Internet
Author: User
This article mainly introduces how js achieves multiple motion effects on the same page. it involves javascript techniques for operating the motion effects of page elements and is of great practical value, for more information about how to implement multiple motion effects on the same page in JavaScript, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

The implementation principle is to add events to these five elements and loops during the call. Note that the timers of each element must be separated.

Key aspect 1:

var speed = (target - obj.offsetWidth)/8;

The buffering effect starts quickly and then slows down until it stops.

speed = speed>0?Math.ceil(speed):Math.floor(speed);

If the speed is greater than 0, it is rounded up. if the speed is smaller than 0, it is rounded down.

Key aspect 2:

if(obj.offsetWidth == target){clearInterval(obj.timer);}else{obj.style.width = obj.offsetWidth+speed+"px";}

If the element width is equal to the target value, turn off the timer. Otherwise, the width continues to increase.

Key aspect 3:

For (I = 0; I
 
  

Each element is added with its own timer attribute, its mouse events, and motion functions are called in the mouse events.

Finally, run the following code:

   Untitled DocumentScript window. onload = function () {var runs = document. getElementById ("runs"); var runs_li = runs. getElementsByTagName ("li"); var I = 0; for (I = 0; I
   
    
0? Math. ceil (speed): Math. floor (speed); if (obj. offsetWidth = target) {clearInterval (obj. timer);} else {obj. style. width = obj. offsetWidth + speed + "px";} document. title = obj. offsetWidth + ',' + target;}, 30);} script
    
  
  • 1
  • 2
  • 3
  • 4
  • 5

I hope this article will help you design javascript programs.

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.