日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue实现轮播图完整版,锁定图片元素纵横比

發布時間:2024/1/18 vue 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue实现轮播图完整版,锁定图片元素纵横比 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

代碼

(1)代碼使用 Element官網Carousel 走馬燈完成,自己加了一個自動根據頁面鎖定圖片縱橫比的功能。

(2)imageUrl中的src改成自己的圖片路徑。

?

<template><div><el-carousel trigger="click" type="card" ref="carousel1" :height="height_carousel" :interval="6000" arrow="always"style="width:auto;margin-left: 2%;margin-right: 2%"><el-carousel-item v-for="item in imagesUrl" :key="item.name"><img :src="item.src" style="height:100%;width:100%;" alt="圖片替代文本" :title="item.title"/></el-carousel-item></el-carousel><h1 style="text-align: center;font-size: 48px;">歡迎來到系統主頁</h1></div> </template><script> export default {name: "index",data() {return {imagesUrl: [{name: "1",src: require('@/assets/backImg/1.jpg'),title: "點擊查看大圖",},{name: "2",src: require('@/assets/backImg/2.jpg'),title: "點擊查看大圖",},{name: "3",src: require('@/assets/backImg/4.jpg'),title: "點擊查看大圖",},{name: "4",src: require('@/assets/backImg/5.jpg'),title: "點擊查看大圖",},],height_carousel: "500px",}},mounted: function () {},methods: { //動態獲取元素的寬度,鎖定元素縱橫比setCarouselHeight() {this.$nextTick(() => {const car_width = this.$refs.carousel1.$el.clientWidth;console.log(car_width);this.height_carousel = (car_width * 9 / 16 / 2).toFixed(0) + "px";console.log(this.height_carousel);return this.height_carousel;});}},//created() {window.addEventListener('resize', this.setCarouselHeight)this.setCarouselHeight()},destroyed() {window.removeEventListener('resize', this.setCarouselHeight)},computed: {}, } </script><style scoped>.el-carousel__item h3 {color: #475669;font-size: 14px;opacity: 0.75;line-height: 300px;margin: 0; }.el-carousel__item:nth-child(2n) {background-color: #99a9bf; }.el-carousel__item:nth-child(2n+1) {background-color: #d3dce6; } </style>

?

?

?

總結

以上是生活随笔為你收集整理的vue实现轮播图完整版,锁定图片元素纵横比的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。