日常整理(2)

日常整理(2)

图片宽度自适应

<img class="re-img" src="../../../assets/img/bus/zzmap.jpg"/>

.re-img {
  width: 100%; /* 或者指定宽度 */
  height: auto; /* 高度自适应 */
  object-fit: contain;
}

vue img 自定义渲染src 图片不显示

<img class="index-banner" :src="data.img" />
img:require("@/assets/images/shouye/banner2.png")

锚点跳转 滑动效果

<div id="anchor" class="topTitle_b">{{spanTextSix}}</div>
biaozhu() {
      var targetElem = document.getElementById("anchor")
      var targetPos = targetElem.offsetTop;
      // document.getElementById("anchor").scrollIntoView()
      window.scrollTo({
        top: targetPos,
        behavior: 'smooth'
      })
    }

获取锚点坐标,根据坐标平滑移动

var anchorElement = document.getElementById(id);
      var rect = anchorElement.getBoundingClientRect();
      var x = rect.left + window.pageXOffset;
      var y = rect.top + window.pageYOffset;
      console.log("锚点的坐标值为:(" + x + ", " + y + ")")
      window.scrollTo({
        top: y,
        left: x,
        behavior: 'smooth'
      })

video标签 滚动条滑到video时播放,滑出时暂停 vue 防止多次滚动 报错

<template>
  <div>
    <video ref="video" v-bind:src="videoSrc" muted controls></video>
  </div>
</template>

<script>
export default {
  data() {
    return {
      videoSrc: 'path/to/your/video',
      observer: null
    }
  },
  mounted() {
    this.observer = new IntersectionObserver(this.handleIntersection, { threshold: 0.5 })
    this.observer.observe(this.$refs.video)
  },
  beforeDestroy() {
    if (this.observer) {
      this.observer.unobserve(this.$refs.video)
      this.observer.disconnect()
      this.observer = null
    }
  },
  methods: {
    handleIntersection: _.debounce(entries => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.play()
        } else {
          entry.target.pause()
        }
      })
    }, 100)
  }
}
</script>
<template>
  <div>
    <video ref="video" src="your_video_path" width="640" height="360"></video>
  </div>
</template>

<script>
export default {
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  methods: {
    handleScroll() {
      const video = this.$refs.video;
      const videoTop = video.getBoundingClientRect().top;
      const videoBottom = video.getBoundingClientRect().bottom;
      const isVisible = (videoTop >= 0 && videoBottom <= window.innerHeight);
      if (isVisible) {
        video.play();
      } else {
        video.pause();
      }
    }
  },
  beforeDestroy() {
    window.removeEventListener("scroll", this.handleScroll);
  }
};
</script>
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值