vue2 pc商城 商品详情页

   <div
      style="
        padding-top: 100px;
        display: flex;
        justify-content: center; /* 在主轴上居中对齐 */
        align-items: center; /* 在交叉轴上居中对齐 */
      "
    >
      <div class="wos-df">
        <div>
          <div style="width: 500px; height: 500px">
            <img :src="mainImgUrl" style="width: 100%; height: 100%" />
          </div>

          <div style="margin-top: -4vw">
            <i class="el-icon-arrow-left" @click="imgLeft()"></i>
            <ul class="Img_ul"   >
              <li 
             
                v-for="(item, index) in imgUrlList"
                :key="index"
                class="Img_li"
                :style="imgStyle"
                @click="changeImg(item, index)"
              >
                <img
                  :class="index === imgActiveIndex ? 'img_activeBorder' : ''"
                  :src="item"
                  style="width: 100px; height: 100px"
                />
              </li>
            </ul>
            <i class="el-icon-arrow-right" @click="imgRight()"></i>
          </div>
        </div>
      </div>
      <div style="margin-left: 25px">
        <div class="a2">
          <h2 class="container">
            提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)
            提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)
            提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)提拉米苏(约2磅)
          </h2>
          <div class="a21">
            <div class="a211">+
              <span class="color">售价:</span>
              <span class="prices">198</span>
              <span class="color">元</span>
              <span class="shic" style="margin-left: 50px; font-size: 18px"
                >原价:<span
                  class="prices2"
                  style="font-size: 30px; font-weight: 700; margin-left: 10px"
                  >198</span
                ></span
              >
              <span>元</span>
            </div>
            <div class="wos-df" style="margin-top: 40px">
              <div class="zhichi">支持全国</div>
            </div>
            <div class="a23">
              <p></p>
              <span class="color">区域:</span>
              <span>北京、上海、广州、深圳、天津、重庆、南京、长沙 </span>
            </div>

            <div class="a25">
              <a class="buttonClass1">联系卖家</a>
            </div>
          </div>
        </div>
      </div>
    </div>
 data () {
    return {
      mainImgUrl: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
      imgUrlList: [
        'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
        'https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg',
        'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
        'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
        'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
        'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg',
        'https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg',
        'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
        'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
        'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
        'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg'
      ],
      imgActiveIndex: 0, // 当前移动图片的索引值
      imgDistance: -30, // 移动的距离
      allDistance: - 30, // 总移动距离
      index: 0,
      calleft: 0

    }
  },
  computed: {
    imgStyle () {
      return {
        transform: `translate3d(${this.imgDistance}px, 0, 0)` // 计算移动的距离(x,y,z)
      }
    }
  },


  methods: {
    changeImg (item, index) {
      this.mainImgUrl = item
      let move= this.imgActiveIndex
      this.imgActiveIndex = index
          if (this.imgActiveIndex >=3&&move< this.imgActiveIndex) {
          this.allDistance = -66 * (this.imgActiveIndex - 4)
          var index1 = 0
          const temp = window.setInterval(() => {
            if (index1 < 33) {
              this.imgDistance-= 4// 每次向右移动的距离
              index1++
              return
            } else {
              window.clearInterval(temp)
            }
          }, 10)
        }
        if (this.imgActiveIndex >=1&&move> this.imgActiveIndex) {
          this.allDistance = -66 * (this.imgActiveIndex - 4)
          var index1 = 0
          const temp = window.setInterval(() => {
            if (index1 < 33) {
              this.imgDistance+= 4// 每次向右移动的距离
              index1++
              return
            } else {
              window.clearInterval(temp)
            }
          }, 10)
        }
  

    },
    imgLeft () {
      if (this.imgActiveIndex > 0) {
        this.imgActiveIndex--  // 索引值-1
        this.imgUrlList.forEach((item, index) => { // 循环小图,通过判断索引值赋值给大图
          if (this.imgActiveIndex === index) {
            this.mainImgUrl = item
          }
        })
      }

      if (this.imgActiveIndex > 1) {
        var index = 0
        const temp = window.setInterval(() => { // 利用定时器实现图片左右移动的动画效果
          if (index < 33) { // 移动次数(33次)
            this.imgDistance += 4 // 每次向左移动的距离 (移动总距离为33*this.imgDistance)
            index++
            return
          } else {
            window.clearInterval(temp) // 移动完清除定时器
          }
        }, 10)
      }
    },
    imgRight () {
      if (this.imgActiveIndex < this.imgUrlList.length - 1) {
        this.imgActiveIndex++
        this.imgUrlList.forEach((item, index) => {
          if (this.imgActiveIndex === index) {
            this.mainImgUrl = item
          }
        })
  
        console.log(this.imgActiveIndex)
        if (this.imgActiveIndex >= 3) {
          this.allDistance = -66 * (this.imgActiveIndex - 4)
          var index = 0
          console.log(this.allDistance)

          const temp = window.setInterval(() => {
            if (index < 33) {
              this.imgDistance -= 4 // 每次向右移动的距离
              index++
              return
            } else {
              window.clearInterval(temp)
            }
          }, 10)
        }
      } else if (this.imgActiveIndex === this.imgUrlList.length - 1) { // 到达最后一张图片,再点击跳转回第一张
        this.imgActiveIndex = 0
        this.mainImgUrl = this.imgUrlList[0]
        var index = 0
        const temp = window.setInterval(() => { // 利用定时器实现图片左右移动的动画效果
          if (index < Math.abs(this.allDistance / 2)) { // 取绝对值再除
            this.imgDistance += (this.imgUrlList.length-5.7) // 每次向左移动的距离 (移动总距离为33*this.imgDistance)
            index++
            return
          } else {
            window.clearInterval(temp) // 移动完清除定时器
          }
        }, 1)
      }
    }
  },

  // 移动
  move () {
    this.timer = setInterval(this.starmove, 2500)
  },
  // 开始移动
  starmove () {
    this.calleft -= 340
    if (this.calleft < -1200) {
      this.calleft = 0
    }
  },
  // 鼠标悬停时停止移动
  stopmove () {
    clearInterval(this.timer)
  },
  // 点击按钮左移
  zuohua () {
    this.calleft -= 340
    if (this.calleft < -1200) {
      this.calleft = 0
    }
  },
  // 点击按钮右移
  youhua () {
    this.calleft += 340
    if (this.calleft > 0) {
      this.calleft = -1020
    }
  }
<style scoped lang="scss">
.el-carousel__item[data-v-a83bd3b0]:nth-child(n + 1) {
  background-color: #fff;
}
.zhichi {
  border: 2px solid #ff8d77;
  padding: 5px;
  border-radius: 5px;
  text-align: center;
  color: #ff4326;
  line-height: 15px;
}
.w {
  width: 1100px;
  margin: 0 auto;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}
.head {
  width: 99vw;
  height: 12vh;
  background-color: #3e8c97;
}
a {
  cursor: pointer;
}

.Img_ul {
  position: relative;
  display: flex;
  left: 10px;
  width: 420px;
  height: 150px;
  overflow: hidden;
  list-style: none;
}
.Img_li {
  float: left;
  margin: 0 8px;
  cursor: pointer;
  box-sizing:border-box;
}
.img_activeBorder {
  border: 3px solid #0dcc73;
}
.img_activeBorder {
  border: 3px solid #0dcc73;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(n) {
  background-color: #99a9bf;
  // text-align: center;
  padding-left: 30px;
  box-sizing: border-box;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.width {
  width: 11.25rem;
  font-size: 14px;
  margin-left: 8px;
  &:nth-child(1) {
    width: 74px;
  }
}
.a2 {
  margin-left: 30px;
}

.a21 .color {
  color: #758188;
}

.a21 .a211 {
  height: 87px;
  // text-align: center;
  line-height: 87px;
  background-color: #f2f5f8;
  color: #758188;
  padding-left: 20px;
}

.a21 .a211 .prices,
.shic {
  margin-left: 10px;
}

.a21 .a211 .prices {
  color: #ff4f0d;
  font-size: 35px;
  font-weight: bold;
}

.a21 .a211 .prices2 {
  text-decoration: line-through;
}

.a21 .a211 .yis {
  margin-left: 230px;
}
.container {
  width: 22vw;
  overflow: hidden; /* 超出部分隐藏 */
  display: -webkit-box; /* 使用-webkit-box布局 */
  -webkit-box-orient: vertical; /* 垂直方向排列内容 */
  -webkit-line-clamp: 2; /* 最多显示两行 */
  text-overflow: ellipsis; /* 超出部分用省略号表示 */
}
.a22 {
  background-color: #f6f9fb;
}

.a22 span,
p {
  margin-top: 10px;
}

.a22 .neir {
  margin-left: 50px;
}

.a23 {
  /* margin-top: 10px; */
  margin-top: 50px;
}

.a24 {
  margin-top: 10px;
}

.a24 .bang {
  display: inline-block;
  border: 3px #edf0f5 solid;
  width: 50px;
  line-height: 40px;
  margin-left: 30px;
  text-align: center;
}

.a24 .bang:hover {
  border: 3px #ff4f0d solid;
}
.aa {
  border: 3px #ff4f0d solid;
}
.a25 {
  margin-top: 50px;
}

.a25 button {
  display: inline-block;
  width: 150px;
  height: 50px;
  border-radius: 5px;
  margin-left: 30px;
}
.el-icon-arrow-left {
  height: 80px;
  background-color: #f7f7f7;
  font-size: 25px;
  text-align: center;
  line-height: 80px;
  display: inline-block;
  position: relative;
  top: 110px;
  right: 10px;
  cursor: pointer;
  color: #000;
}
.el-icon-arrow-right {
  height: 80px;
  line-height: 80px;
  background-color: #f7f7f7;
  font-size: 25px;
  display: inline-block;
  position: relative;
  left: 480px;
  top: -150px;
  cursor: pointer;
  color: #000;
}
.a25 .a25color1 {
  background-color: #ff2a00;
  color: #fff;
  font-size: 20px;
  font-weight: bolder;
  border: 1px #ff4f0d solid;
}
.buttonClass1 {
  color: #fff;
  font-size: 20px;
  border-radius: 10px;
  font-weight: 700;
  background-color: #ff2a00;
  display: inline-block;
  width: 185px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
</style>

效果图

 目前没有放大镜功能 后续添加

备用代码 

   changeImg (item, index) {
      this.mainImgUrl = item
      let move = this.imgActiveIndex
      this.imgActiveIndex = index
      if (this.imgActiveIndex >= 3 && move < this.imgActiveIndex) {
        this.allDistance = -66 * (this.imgActiveIndex - 4)
        var index1 = 0
        const temp = window.setInterval(() => {
          if (index1 < 33) {
            this.imgDistance -= 4// 每次向右移动的距离
            index1++
            return
          } else {
            window.clearInterval(temp)
          }
        }, 10)
      }
      if (this.imgActiveIndex >= 1 && move > this.imgActiveIndex) {
        this.allDistance = -66 * (this.imgActiveIndex - 4)
        var index1 = 0
        const temp = window.setInterval(() => {
          if (index1 < 33) {
            this.imgDistance += 4// 每次向右移动的距离
            index1++
            return
          } else {
            window.clearInterval(temp)
          }
        }, 10)
      }


    },
    imgLeft () {
      if (this.imgActiveIndex > 0) {
        this.imgActiveIndex--  // 索引值-1
        this.imgUrlList.forEach((item, index) => { // 循环小图,通过判断索引值赋值给大图
          if (this.imgActiveIndex === index) {
            this.mainImgUrl = item
          }
        })
      }

      if (this.imgActiveIndex > 1) {
        var index = 0
        const temp = window.setInterval(() => { // 利用定时器实现图片左右移动的动画效果
          if (index < 33) { // 移动次数(33次)
            this.imgDistance += 4 // 每次向左移动的距离 (移动总距离为33*this.imgDistance)
            index++
            return
          } else {
            window.clearInterval(temp) // 移动完清除定时器
          }
        }, 10)
      }
    },
    imgRight () {
      if (this.imgActiveIndex < this.imgUrlList.length - 1) {
        this.imgActiveIndex++
        this.imgUrlList.forEach((item, index) => {
          if (this.imgActiveIndex === index) {
            this.mainImgUrl = item
          }
        })


        if (this.imgActiveIndex >= 3) {
          this.allDistance = -66 * (this.imgActiveIndex - 4)
          var index = 0


          const temp = window.setInterval(() => {
            if (index < 33) {
              this.imgDistance -= 4 // 每次向右移动的距离
              index++
              return
            } else {
              window.clearInterval(temp)
            }
          }, 10)
        }
      } else if (this.imgActiveIndex === this.imgUrlList.length) { // 到达最后一张图片,再点击跳转回第一张
        this.imgActiveIndex = 0
        this.mainImgUrl = this.imgUrlList[0]
        var index = 0
        const temp = window.setInterval(() => { // 利用定时器实现图片左右移动的动画效果
          if (index < Math.abs(this.allDistance / 2)) { // 取绝对值再除
            this.imgDistance += (this.imgUrlList.length - 5.7) // 每次向左移动的距离 (移动总距离为33*this.imgDistance)
            index++
            return
          } else {
            window.clearInterval(temp) // 移动完清除定时器
          }
        }, 1)
      }
    }

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值