About the implementation of JavaScript carousel stay effect

不言
Release: 2018-07-04 10:22:53
Original
1092 people have browsed it

The following article will share with you the ideas for implementing the JavaScript carousel stay effect. Carousel stay is very similar to wireless scrolling. They both use attributes and variables to control movement to achieve carousel. Friends who are interested, let’s take a look

1. Ideas

1. Carousel stay is very similar to wireless scrolling, both use attributes And variable control movement to achieve carousel;

2. The difference is that the carousel stay needs to add transition attributes and timers to achieve the carousel stay effect;

2 , Steps

1. Write the basic structure style

. You need to add one more picture that is the same as the first one at the end to eliminate switching. Jitter;

2. Add the carousel stay event. With the previous foundation, directly add the index circle default event to the carousel stay event;

Note: When When the carousel reaches the last picture, the transition needs to be eliminated. The setTimeout timer is used here. There is no delay after the last picture of the card is rotated, and it jumps directly to the first picture. Since the first picture is the same as the last picture, so It will form a visual blind spot, which looks like a continuous carousel effect;

//轮播停留方法 function move() { box.className = "box anmint"; circle[count].style.backgroundColor = ""; count++; box.style.marginLeft = (-800 * count) + "px"; //最后一张走完之后,执行一次定时器不循环,卡过渡时间,消除切换 setTimeout(function () { if (count >= 6) { count = 0; box.className = "box"; //marginLeft=0之前去除过渡属性 box.style.marginLeft = "0px"; } circle[count].style.backgroundColor = "red"; }, 500); }
Copy after login

3. Add the event of entering the index circle

This is basically the same as the fade-in and fade-out into the index circle event. The difference is that there is no need to call the carousel stay event, and the current index is directly used to index the image to follow the transformation; note that thecount=this.indexvalue must be marked at the end. , so that when the default behavior is executed again, the default behavior will be executed backwards immediately following the currently displayed picture;

//进入索引圈事件 for(var j=0;j
        
Copy after login

4. Improve the mouse entry and exit code

Rendering:

Full code:

    JS轮播停留效果   

Copy after login

That’s it The entire content of this article is hoped to be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About how to use the vue.js carousel chart component

VUE 3D carousel chart encapsulation implementation method

The above is the detailed content of About the implementation of JavaScript carousel stay effect. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!