国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Vue實現(xiàn)圖片輪播組件思路及實例解析

瀏覽:3日期:2023-01-21 16:42:48

1、先看效果:

Vue實現(xiàn)圖片輪播組件思路及實例解析

熟悉的圖片輪播,只要是個網站,百分之90以上會有個圖片輪播。我認為使用圖片輪播。

第一可以給人以一種美觀的感受,而不會顯得網站那么呆板,

第二可以增加顯示內容,同樣的區(qū)域可以顯示更多內容。

 2、每學一個新東西 ,圖片輪播都是很好的練手案例,而且,也很實用。

3、基本要求:頁面加載,自動播放。鼠標懸停,停止播放。鼠標離開,繼續(xù)播放

點擊左右箭頭切換上一張,下一張圖片。

下方小圓點顯示當前位第幾張圖片。

 4、使用Vue實現(xiàn)

 5、示例代碼

結構html:

<template> <div id='slider'> <div @mouseover='stop' @mouseleave='play'> <ul :style='containerStyle'> <li> <img : :src='http://m.cgvv.com.cn/bcjs/sliders[sliders.length - 1].img' alt=''> </li> <li v-for='(item, index) in sliders' :key='index'> <img : :src='http://m.cgvv.com.cn/bcjs/item.img' alt=''> </li> <li> <img : :src='http://m.cgvv.com.cn/bcjs/sliders[0].img' alt=''> </li> </ul> <ul class='direction'> <li @click='move(600, 1, speed)'> <svg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg'><path fill='#ffffff' d='M481.233 904c8.189 0 16.379-3.124 22.628-9.372 12.496-12.497 12.496-32.759 0-45.256L166.488 512l337.373-337.373c12.496-12.497 12.496-32.758 0-45.255-12.498-12.497-32.758-12.497-45.256 0l-360 360c-12.496 12.497-12.496 32.758 0 45.255l360 360c6.249 6.249 14.439 9.373 22.628 9.373z' /></svg> </li> <li @click='move(600, -1, speed)'> <svg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg'><path fill='#ffffff' d='M557.179 904c-8.189 0-16.379-3.124-22.628-9.372-12.496-12.497-12.496-32.759 0-45.256L871.924 512 534.551 174.627c-12.496-12.497-12.496-32.758 0-45.255 12.498-12.497 32.758-12.497 45.256 0l360 360c12.496 12.497 12.496 32.758 0 45.255l-360 360c-6.249 6.249-14.439 9.373-22.628 9.373z' /></svg> </li> </ul> <ul class='dots'> <li v-for='(dot, i) in sliders' :key='i' : @click = jump(i+1) > </li> </ul> </div> </div></template>

CSS部分:

*{ box-sizing: border-box; margin:0; padding:0; } ol,ul{ list-style: none; } #slider{ text-align: center; } .window{ position:relative; width:600px; height:400px; margin:0 auto; overflow:hidden; } .container{ display:flex; position:absolute; } .left, .right{ position:absolute; top:50%; transform:translateY(-50%); width:50px; height:50px; background-color:rgba(0,0,0,.3); border-radius:50%; cursor:pointer; } .left{ left:3%; padding-left:12px; padding-top:10px; } .right{ right:3%; padding-right:12px; padding-top:10px; } img{ user-select: none; } .dots{ position:absolute; bottom:10px; left:50%; transform:translateX(-50%); } .dots li{ display:inline-block; width:15px; height:15px; margin:0 3px; border:1px solid white; border-radius:50%; background-color:#333; cursor:pointer; } .dots .dotted{ background-color:orange; }

JavaScript部分:

script>export default { name: ’slider’, props: { initialSpeed: { type: Number, default: 30 }, initialInterval: { type: Number, default: 3 } }, data () { return { sliders:[ { img:’http://img.hb.aicdn.com/adbde61e4343dedd21e97ea7f22666825a8db7d077ffe-qn8Pjn_fw658’ }, { img:’http://img.hb.aicdn.com/adeed7d28df6e776c2fa6032579c697381d1a82b7fe00-fwRqgn_fw658’ }, { img:’http://img.hb.aicdn.com/ab7f48509b3c0353017d9a85ef1d12400c9b2724540d4-p3zouo_fw658’ }, { img:’http://img.hb.aicdn.com/60f788fc2a846192f224b9e6d4904b30e54926211d3d67-ACFJ9G_fw658’ }, { img:’http://img.hb.aicdn.com/22ded455284aab361b8d2056e82f74a891a019704296a-PSraEB_fw658’ }, ], imgWidth:600, currentIndex:1, distance:-600, transitionEnd: true, speed: this.initialSpeed } }, computed:{ containerStyle() { return { transform:`translate3d(${this.distance}px, 0, 0)` } }, interval() { return this.initialInterval * 1000 } }, mounted() { this.init() }, methods:{ init() { this.play() window.onblur = function() { this.stop() }.bind(this) window.onfocus = function() { this.play() }.bind(this) }, move(offset, direction, speed) { console.log(speed) if (!this.transitionEnd) return this.transitionEnd = false direction === -1 ? this.currentIndex += offset/600 : this.currentIndex -= offset/600 if (this.currentIndex > 5) this.currentIndex = 1 if (this.currentIndex < 1) this.currentIndex = 5 const destination = this.distance + offset * direction this.animate(destination, direction, speed) }, animate(des, direc, speed) { if (this.temp) { window.clearInterval(this.temp); this.temp = null ; } this.temp = window.setInterval(() => { if ((direc === -1 && des < this.distance) || (direc === 1 && des > this.distance)) { this.distance += speed * direc } else { this.transitionEnd = true window.clearInterval(this.temp) this.distance = des if (des < -3000) this.distance = -600 if (des > -600) this.distance = -3000 } }, 20) }, jump(index) { const direction = index - this.currentIndex >= 0 ? -1 : 1; const offset = Math.abs(index - this.currentIndex) * 600; const jumpSpeed = Math.abs(index - this.currentIndex) === 0 ? this.speed : Math.abs(index - this.currentIndex) * this.speed ; this.move(offset, direction, jumpSpeed) }, play() { if (this.timer) { window.clearInterval(this.timer) this.timer = null } this.timer = window.setInterval(() => { this.move(600, -1, this.speed) }, this.interval) }, stop() { window.clearInterval(this.timer) this.timer = null } }}</script>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 美国毛片免费观看 | 大陆高清自拍 | 国产综合精品久久亚洲 | 欧美一级va在线视频免费播放 | 中文字幕亚洲高清综合 | 手机在线播放av | 国产欧美日韩精品第三区 | 九九九九九九精品免费 | 欧美大片欧美毛片大片 | 国产成人a在一区线观看高清 | 国产成人刺激视频在线观看 | 99国产小视频| 欧美a在线| 国产欧美日韩亚洲 | 亚洲精品69 | 亚洲视频网站在线观看 | 日本特黄特色视频 | 免费看美女无遮掩的软件 | 精品久久在线 | 亚洲欧美激情精品一区二区 | 一色屋色费精品视频在线观看 | 亚洲欧美高清 | 亚洲欧美综合国产精品一区 | 深爱激情五月网 | 青青热久久国产久精品秒播 | 九九国产视频 | 亚洲男人的天堂久久精品 | 日韩精品视频免费在线观看 | 国产精品综合一区二区 | 亚洲一区二区精品 | 日韩欧美精品在线视频 | 午夜在线伦理福利视频 | 国产免费一区二区在线看 | 成人看片在线观看免费 | 成年午夜性爽快免费视频不卡 | 99久热在线精品视频播 | 日韩一级精品视频在线观看 | 久久综合精品国产一区二区三区无 | 成人国产一区二区三区精品 | 无码孕妇孕交在线观看 | 亚洲国产系列久久精品99人人 |