最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue.js實(shí)現(xiàn)點(diǎn)擊左右按鈕圖片切換

 更新時(shí)間:2022年07月12日 17:25:45   作者:南城巷陌  
這篇文章主要為大家詳細(xì)介紹了Vue.js實(shí)現(xiàn)點(diǎn)擊左右按鈕圖片切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vue.js實(shí)現(xiàn)點(diǎn)擊左右按鈕圖片切換的具體代碼,供大家參考,具體內(nèi)容如下

關(guān)于圖片切換,網(wǎng)上也有很多的說法,這邊通過參考給出了如下所示的解決方案

效果:

html

通過v-for循環(huán)展示圖片列表itemlist,將圖片路徑保存在data中的itemlist中,添加上下按鈕的點(diǎn)擊事件。

<template>
? <div>
? ? <div class="zs-adv">
? ? ? <a title="上一頁" :href="'#'" class="adv-pre" @click="leftScroll">上一個(gè)</a>
? ? ? <div id="adv-pad-scroll">
? ? ? ? <div class="adv-pad">
? ? ? ? ? <img
? ? ? ? ? ? ? class="adv-pad-item"
? ? ? ? ? ? ? v-for="(item, index) in itemlist"
? ? ? ? ? ? ? :key="index"
? ? ? ? ? ? ? alt=""
? ? ? ? ? ? ? :ref="`item${index}`"
? ? ? ? ? ? ? :src="item.src"
? ? ? ? ? />
? ? ? ? </div>
? ? ? </div>
? ? ? <a title="下一頁" :href="'#'"  class="adv-next" @click="rightScroll">下一個(gè)</a>
? ? </div>
? </div>
</template>

js 

通過點(diǎn)擊事件去執(zhí)行響應(yīng)過程

<script>
? export default {
? ? name: "index",
? ? components: {},
? ? data() {
? ? ? return {
? ? ? ? maxClickNum: 0, // 最大點(diǎn)擊次數(shù)
? ? ? ? lastLeft: 0, // 上次滑動(dòng)距離
? ? ? ? clickNum: 0, // 點(diǎn)擊次數(shù)
? ? ? ? itemlist: [
? ? ? ? ? {
? ? ? ? ? ? id: 0,
? ? ? ? ? ? src: require("./image/1.png"),
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? id: 1,
? ? ? ? ? ? src: require("./image/2.png"),
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? id: 2,
? ? ? ? ? ? src: require("./image/3.png"),
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? id: 3,
? ? ? ? ? ? src: require("./image/4.png"),
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? id: 4,
? ? ? ? ? ? src: require("./image/5.png"),
? ? ? ? ? },
? ? ? ? ? {
? ? ? ? ? ? id: 5,
? ? ? ? ? ? src: require("./image/6.png"),
? ? ? ? ? },
? ? ? ? ],
? ? ? ? // imgx: 0,
? ? ? ? // form: this.$form.createForm(this, { name: "horizontal_login" }),
? ? ? };
? ? },
? ? //函數(shù)
? ? methods: {
? ? ? leftScroll() {
? ? ? ? if (this.clickNum > 0) {
? ? ? ? ? // 獲取當(dāng)前元素寬度
? ? ? ? ? console.log(document.querySelectorAll(".adv-pad-item"));
? ? ? ? ? let width =
? ? ? ? ? ? document.querySelectorAll(".adv-pad-item")[this.clickNum - 1]
? ? ? ? ? ? ? .offsetWidth;
? ? ? ? ? // 公示:滾動(dòng)距離(元素的magin-left值) = 它自己的長(zhǎng)度 + 上一次滑動(dòng)的距離
? ? ? ? ? console.log(document.getElementsByClassName("adv-pad"));
? ? ? ? ? document.getElementsByClassName("adv-pad")[0].style.marginLeft = `${
? ? ? ? ? ? this.lastLeft + width
? ? ? ? ? }px`;
? ? ? ? ? this.lastLeft = width + this.lastLeft;
? ? ? ? ? // 點(diǎn)擊次數(shù)-3
? ? ? ? ? this.clickNum = this.clickNum - 1;
? ? ? ? ? // 如果點(diǎn)擊次數(shù)小于最大點(diǎn)擊次數(shù),說明最后一個(gè)元素已經(jīng)不在可是區(qū)域內(nèi)了,顯示右箭頭
? ? ? ? ? if (this.clickNum < this.maxClickNum) {
? ? ? ? ? ? this.showRightIcon = true;
? ? ? ? ? }
? ? ? ? }
? ? ? },
? ? ? rightScroll() {
? ? ? ? // 如果點(diǎn)擊次數(shù)小于數(shù)組長(zhǎng)度-1時(shí),執(zhí)行左滑動(dòng)效果。
? ? ? ? if (this.clickNum < this.itemlist.length - 1) {
? ? ? ? ? // 獲取當(dāng)前元素寬度
? ? ? ? ? let width =
? ? ? ? ? ? document.querySelectorAll(".adv-pad-item")[this.clickNum].offsetWidth;
? ? ? ? ? // 獲取最后一個(gè)元素距離左側(cè)的距離
? ? ? ? ? let lastItemOffsetLeft =
? ? ? ? ? ? document.getElementsByClassName("adv-pad-item")[
? ? ? ? ? ? this.itemlist.length - 1
? ? ? ? ? ? ? ].offsetLeft;
? ? ? ? ? // 獲取可視區(qū)域?qū)挾?
? ? ? ? ? const lookWidth = document.getElementById("adv-pad-scroll").clientWidth;
? ? ? ? ? // 如果最后一個(gè)元素距離左側(cè)的距離大于可視區(qū)域的寬度,表示最后一個(gè)元素沒有出現(xiàn),執(zhí)行滾動(dòng)效果
? ? ? ? ? if (lastItemOffsetLeft > lookWidth) {
? ? ? ? ? ? // 公示:滾動(dòng)距離(元素的magin-left值) = 負(fù)的它自己的長(zhǎng)度 + 上一次滑動(dòng)的距離
? ? ? ? ? ? document.getElementsByClassName("adv-pad")[0].style.marginLeft = `${
? ? ? ? ? ? ? -width + this.lastLeft
? ? ? ? ? ? }px`;
? ? ? ? ? ? this.lastLeft = -width + this.lastLeft;
? ? ? ? ? ? // 點(diǎn)擊次數(shù)+3
? ? ? ? ? ? this.clickNum += 1;
? ? ? ? ? ? // 記錄到最后一個(gè)元素出現(xiàn)在可視區(qū)域時(shí),點(diǎn)擊次數(shù)的最大值。用于后面點(diǎn)擊左側(cè)箭頭時(shí)判斷右側(cè)箭頭的顯示
? ? ? ? ? ? this.maxClickNum = this.clickNum;
? ? ? ? ? }
? ? ? ? ? this.showRightIcon = lastItemOffsetLeft > lookWidth + width;
? ? ? ? }
? ? ? },
? ? },
? };
</script>

css

<style lang="less" scoped>
? .zs-adv {
? ? margin: 50px auto 0;
? ? width: 1272px;
? ? height: 120px;
? ? background: url("./image/adv-bg.png") top center no-repeat;
?
? ? a {
? ? ? margin-top: 58px;
? ? ? width: 16px;
? ? ? height: 24px;
? ? ? opacity: 0.8;
? ? }
?
? ? a:hover {
? ? ? opacity: 1;
? ? }
?
? ? .adv-pre {
? ? ? float: left;
? ? ? margin-right: 20px;
? ? }
?
? ? .adv-next {
? ? ? float: right;
? ? }
?
? ? #adv-pad-scroll {
? ? ? float: left;
? ? ? width: 1200px;
? ? ? overflow: hidden;
? ? ? .adv-pad {
? ? ? ? width: 2400px;
? ? ? ? height: 120px;
? ? ? ? .adv-pad-item {
? ? ? ? ? padding: 20px 10px 0px 10px;
? ? ? ? ? width: 400px;
? ? ? ? ? height: 100px;
? ? ? ? ? cursor: pointer;
? ? ? ? ? animation: all 1.5s;
? ? ? ? }
?
? ? ? ? .adv-pad-item:hover {
? ? ? ? ? padding: 10px 5px 0px 10px;
? ? ? ? }
? ? ? }
? ? }
? }
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue2+elementUI的el-tree的懶加載功能

    vue2+elementUI的el-tree的懶加載功能

    這篇文章主要介紹了vue2+elementUI的el-tree的懶加載,文中給大家提到了element?ui?中?el-tree?實(shí)現(xiàn)懶加載的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • 解決vue單頁面修改樣式無法覆蓋問題

    解決vue單頁面修改樣式無法覆蓋問題

    這篇文章主要介紹了vue單頁面修改樣式無法覆蓋問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Vue實(shí)現(xiàn)導(dǎo)出excel表格功能

    Vue實(shí)現(xiàn)導(dǎo)出excel表格功能

    這篇文章主要介紹了Vue實(shí)現(xiàn)導(dǎo)出excel表格的功能,在文章末尾給大家提到了vue中excel表格的導(dǎo)入和導(dǎo)出代碼,需要的朋友可以參考下
    2018-03-03
  • vue3如何監(jiān)聽頁面的滾動(dòng)

    vue3如何監(jiān)聽頁面的滾動(dòng)

    這篇文章主要給大家介紹了關(guān)于vue3如何監(jiān)聽頁面的滾動(dòng)的相關(guān)資料,在vue中實(shí)現(xiàn)滾動(dòng)監(jiān)聽和原生js無太大差異,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • Vue中使用防抖與節(jié)流的方法

    Vue中使用防抖與節(jié)流的方法

    這篇文章主要為大家介紹了Vue中使用防抖與節(jié)流的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • vue中的雙向數(shù)據(jù)綁定原理與常見操作技巧詳解

    vue中的雙向數(shù)據(jù)綁定原理與常見操作技巧詳解

    這篇文章主要介紹了vue中的雙向數(shù)據(jù)綁定原理與常見操作技巧,結(jié)合實(shí)例形式詳細(xì)分析了vue中雙向數(shù)據(jù)綁定的概念、原理、常見操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2020-03-03
  • vue權(quán)限問題的完美解決方案

    vue權(quán)限問題的完美解決方案

    今天來說說權(quán)限管理,因?yàn)榫W(wǎng)上已經(jīng)有很多關(guān)于這方面的很多內(nèi)容,下面這篇文章主要給大家介紹了關(guān)于vue權(quán)限問題的完美解決方案,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • vue學(xué)習(xí)筆記之v-if和v-show的區(qū)別

    vue學(xué)習(xí)筆記之v-if和v-show的區(qū)別

    本篇文章主要介紹了vue學(xué)習(xí)筆記之v-if和v-show的區(qū)別,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • Vue + Webpack + Vue-loader學(xué)習(xí)教程之相關(guān)配置篇

    Vue + Webpack + Vue-loader學(xué)習(xí)教程之相關(guān)配置篇

    這篇文章主要介紹了關(guān)于Vue + Webpack + Vue-loader的相關(guān)配置篇,文中通過示例代碼介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • 后臺(tái)使用freeMarker和前端使用vue的方法及遇到的問題

    后臺(tái)使用freeMarker和前端使用vue的方法及遇到的問題

    這篇文章主要介紹了后臺(tái)使用freeMarker和前端使用vue的方法及遇到的問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06

最新評(píng)論

临高县| 元朗区| 石狮市| 沧州市| 固镇县| 七台河市| 胶南市| 岑巩县| 璧山县| 永福县| 汶上县| 平潭县| 丹阳市| 格尔木市| 东光县| 林周县| 慈利县| 高密市| 尉犁县| 丹江口市| 托克托县| 张掖市| 濉溪县| 广南县| 衡南县| 阿克苏市| 蕲春县| 吐鲁番市| 沙洋县| 石林| 简阳市| 和林格尔县| 昆明市| 阿拉善盟| 湖北省| 民乐县| 马边| 泰和县| 台中市| 原平市| 宝清县|