Js cool ball running along the straight line navigation bar special effects source code sharing

Source: Internet
Author: User

Js cool ball running along the straight line navigation bar special effects source code sharing

 

I have been working on an enterprise website recently. Today, I want to share a front-end demo with JavaScript.

The main effect, first. As follows:

Ha ~ I have stolen the logo of the Code. Don't blame me.

Because it is not deployed on the internet, I will describe the main animation effects!

First effect: There is a ball in it that will run along the red lines. when it encounters a circle, it will circle and then run a straight line. When it encounters a circle, it will run around the circle, this is the first animation effect until you finish running all the straight lines and start running again.

Second effect: when the data is suspended on any circle, the ball will always run around the circle until the mouse http: // mark leaves. When the mouse leaves, the ball starts to run at the starting position.

Let's talk about the principle: in fact, the position offset in css is used, and the ball is a gif dynamic image. The fact that css is used to change the position of the ball leads to the effect we see. There are two main effects: linear motion and circular motion.

The core code of linear motion:

1 $('#point').css({left:(startX++)+'px',top:startY});

The main core code of the circle is as follows:

1 startX = circleX-(Math.cos(angle)*radius);
2 startY = circleY-(Math.sin(angle)*radius);
3 $('#point').css({left:startX+'px',top:startY});

Use the two functions cos () and sin () in high school mathematics to draw circles.

 


 

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.