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
1. Install Zabbix Agent to monitor the local mach...
Table of contents 1. Core 1. Get the Dom node 2. ...
1. Create a test table CREATE TABLE `mysql_genara...
Let's first look at some simple data: Accordin...
background Search the keyword .htaccess cache in ...
Table of contents 1. Tool Introduction 2. Workflo...
Table of contents 1. Create objects by literal va...
Table of contents Preface 1. Local port forwardin...
This article shares the specific code of JavaScri...
This article shares with you the graphic tutorial...
error message: ERROR 1862 (HY000): Your password ...
v-for directive Speaking of lists, we have to men...
Scenario: After installing the latest version of ...
String extraction without delimiters Question Req...
When changing the time zone under Linux, it is al...