This article example shares the specific code of Vue to achieve the frame rate playback of the carousel for your reference. The specific content is as follows need Pass in an array containing directory names. Through this directory name, read all the pictures in the file directory and play them in a loop, forming an effect of playing a certain number of pictures every 1 second. After the last directory is played, jump to the first directory and play it in a loop. Core: Use an API of webpack require.contex to read the file name in the directory. If you want to know more, you can check it out. CodeHTML <template> <div id="imgPlay" ref="container" :style="[style]"> <img :src="imgsrc" :style="[{height:style.height,width:style.width}]"> <div id="but"> <button @click="start()">Start</button> <button @click="stop()">Stop</button> </div> </div> </template> javascript <script> export default { name: 'ZxImgPlay', data () { return { style:[ width:"50px", height:"50px" ], interval: null, // timer id flag: true, // Timer switch setIntervalNumber: 0, // Current displayed image subscript imgsrc: "", // Image path to be displayed imgUrls: [], // All image paths frameRate: 0 // Frame rate } }, computed: {}, watch: {}, created () { }, mounted () { this.zxInit() }, beforeDestroy () { }, methods: { zxInit() { //This.DisplayParam is a set of things within the company, and the mixed object //this.DisplayParam.frameRate is an array ["Directory Name 1", "Directory Name 2"] // this.DisplayParam.imgUrls is a dead image. When there is no directory, the dead image is used. // this.DisplayParam.frameRate is the incoming frame rate this.frameRate = this.DisplayParam.frameRate && (1000 / this.DisplayParam.frameRate) this.imgUrls = this.DisplayParam.imgUrls this.DisplayParam.imageFileName != 0 ? this.readdir(this.DisplayParam.imageFileName) : this.showImages(true) }, start () { if (this.flag) return this.showImages() this.flag = true }, stop () { this.flag = false clearInterval(this.interval) }, readImages(imageFileName, _A) { this.stop() let req = require.context("@/../static/images", true, /\.(?:bmp|jpg|gif|jpeg|png)$/).keys(); let path = new RegExp(imageFileName[_A]) req.forEach(item => { if (path.test(item)) { this.imgUrls.push({ img: "@/../static/images/" + imageFileName[_A] + item.substring(item.lastIndexOf('/')) }) } }) this.showImages() }, readdir (imageFileName) { this.imgUrls = [] for (let i = 0; i < imageFileName.length; i++) { this.readImages(imageFileName, i) } }, showImages(_B) { if (_B) this.imgUrls = this.imgUrlsSort(this.imgUrls, 'sort') console.log(this.imgUrls) this.interval = setInterval(this.setIntervalFun, this.frameRate) }, imgUrlsSort (ary, key) { return ary.sort((a, b) => { let x = a[key]; let y = b[key]; return ((x < y) ? -1 : (x > y) ? 1 : 0) }) }, setIntervalFun () { if (this.setIntervalNumber >= this.imgUrls.length) { this.setIntervalNumber = 0 } this.imgsrc = this.imgUrls[this.setIntervalNumber++].img || '' } } } </script> question The above has achieved the function, but two problems have been found so far 1. The first parameter of the require.context() API cannot use a mutable value, such as a variable, and a warning will be issued. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to Dockerize a Python Django Application
>>: What to do if you forget the initial password of MySQL on MAC
Table of contents Preface Check and uninstall Ope...
1. Add users and groups 1. Add mysql user group #...
In this article, the blogger will take you to lea...
Before, I had built WordPress myself, but at that...
Table of contents Preface About webSocket operati...
Using Navicat directly to connect via IP will rep...
1 Start the Docker service First you need to know...
Whitelist rule syntax: BasicRule wl:ID [negative]...
need: According to business requirements, it is n...
System version [root@ ~]# cat /etc/redhat-release...
This article shares the installation and configur...
Windows 10 now supports Linux subsystem, saying g...
The purpose of using cache is to reduce the press...
Table of contents Overview Checking setTimeout() ...
1. The vertical-align property achieves the follo...