简体   繁体   中英

How Do I Combine These Two JQuery Statements?

How do I combine these two JQuery statements? This is for a bootstrap carousel manipulated with JQuery.

$('.carousel').carousel(randomNumber);

and

$('.carousel').carousel({ interval: 6500 })

The first statement sets a random slide, and the second sets the interval. I know this should be relatively easy but I've had some trouble figuring it out and I can't find any other examples.

The two methods are totally different.

This method is to set options for a carousel which can contain interval, pause, and wrap.

$('.carousel').carousel({ interval: 6500, pause: "hover", wrap: true });

However, this method is to set a current slide.

$('.carousel').carousel(number);

It's impossible to call the methods at the same time, but you can use chaining like below:

$('.carousel').carousel({ interval: 6500}).carousel(randomNumber);

Check here

You will see the carousel moving to the 3rd slide as soon as it loads.

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