We can see the carousel descriptions on the official website. here we use an instance to illustrate the implementation effect of the carousel function of a small program: We can see the carousel descriptions on the official website, here is an example to illustrate the implementation of the carousel function of the applet:
Let's take a look at it first:
JS code:
var app = getApp();Page({ data: { imgUrls: [ 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg' ], indicatorDots: true, autoplay: false, interval: 5000, duration: 1000 }, changeIndicatorDots: function(e) { this.setData({ indicatorDots: !this.data.indicatorDots }) }, changeAutoplay: function(e) { this.setData({ autoplay: !this.data.autoplay }) }, intervalChange: function(e) { this.setData({ interval: e.detail.value }) }, durationChange: function(e) { this.setData({ duration: e.detail.value }) },})
Data is the data to be set. Whether the indicatorDots setting is a bit, the interval setting is to switch every several milliseconds, and the duration setting is to set the switching speed. Traverse all the photos. These values are set through data in the function.
WXML code:
The above is the carousel process, the main application component, autoplay sets whether to play automatically, interval sets the switching interval in milliseconds, and duration sets the switching speed. Traverse all the photos.
The carousel effect can be achieved through simple configuration, which is very easy to implement.
For more articles about the carousel function of small programs, please follow the PHP Chinese network!