简体   繁体   中英

How do I properly fade in and out using jQuery?

Can anyone help me with this simple bit of jQuery? I am building a carousel that features many sliding <li> s. Each one has a short description accompanying it, which I want to fade out when the carousel slides, and fade in when the carousel stops at another <li> . The problem is that when the carousel controls are clicked rapidly, the fades take a while to catch up. Also the current simple fadeIn/Out option doesn't work well when clicking to an <li> much further through the carousel (from the small grey discs underneath infographic). I've tried a few options but I'm not really getting anywhere.

The page is here: http://weaver-wp.weavertest.com/radiation-infographic/

Thanks for any help :)

David

The trick is to stop the operation before you start the next one:

http://api.jquery.com/stop/

bottom line, you stop all previous animations before you call in the next one. This avoids building up a queue of animations.

在调用fadeIn / fadeOut之前使用clearQueue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM