vue实现悬浮广告飘窗组件

<template>
  <!--悬浮小广告样式的提示信息-->
  <div
    id="thediv"
    ref="thediv"
    style="position: absolute; z-index: 111; left: 0; top: 0"
    v-show="thedivShow"
    @mouseover="clearFdAd"
    @mouseout="starFdAd"
  >
    <div
      style="
        cursor: pointer;
        text-align: right;
        font-size: 12px;
        color: #999999;
      "
      @click="thedivShow = false"
    >
      关闭
    </div>
    <a
      href="http://xxxxxx" target="_blank""
    ><img src="../../assets/images/tips.png" width="320" border="0" /></a>
  </div>
</template>

<script>
var interval;
export default {
  data() {
    return {
      xPos: 0,
      yPos: 0,
      xin: true,
      yin: true,
      step: 1,
      delay: 18,
      height: 0,
      Hoffset: 0,
      Woffset: 0,
      yon: 0,
      xon: 0,
      pause: true,
      thedivShow: true,
    };
  },

  mounted() {
    interval = setInterval(this.changePos, this.delay);
  },

  methods: {
    changePos() {
      let width = document.documentElement.clientWidth;
      let height = document.documentElement.clientHeight;
      this.Hoffset = this.$refs.thediv.offsetHeight; //获取元素高度
      this.Woffset = this.$refs.thediv.offsetWidth;

      // 滚动部分跟随屏幕滚动
      // this.$refs.thediv.style.left = (this.xPos + document.body.scrollLeft + document.documentElement.scrollLeft) + "px";
      // this.$refs.thediv.style.top = (this.yPos + document.body.scrollTop + document.documentElement.scrollTop) + "px";

      // 滚动部分不随屏幕滚动
      this.$refs.thediv.style.left =
        this.xPos + document.body.scrollLeft + "px";
      this.$refs.thediv.style.top = this.yPos + document.body.scrollTop + "px";

      if (this.yon) {
        this.yPos = this.yPos + this.step;
      } else {
        this.yPos = this.yPos - this.step;
      }
      if (this.yPos < 0) {
        this.yon = 1;
        this.yPos = 0;
      }
      if (this.yPos >= height - this.Hoffset) {
        this.yon = 0;
        this.yPos = height - this.Hoffset;
      }

      if (this.xon) {
        this.xPos = this.xPos + this.step;
      } else {
        this.xPos = this.xPos - this.step;
      }
      if (this.xPos < 0) {
        this.xon = 1;
        this.xPos = 0;
      }
      if (this.xPos >= width - this.Woffset) {
        this.xon = 0;
        this.xPos = width - this.Woffset;
      }
    },
    clearFdAd() {
      clearInterval(interval);
    },
    starFdAd() {
      interval = setInterval(this.changePos, this.delay);
    },
  },
};
</script>

<style lang="scss" scoped>
#thediv {
  z-index: 100;
  position: absolute;
  top: 43px;
  left: 2px;
  height: 184px;
  width: 280px;
  overflow: hidden;
  img{
      width: 100%;
      height: 100%;
  }
}
</style>
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
浮动广告代码 右下角漂浮代码 [removed] initAd();//载入页面后,调用函数initAd() [removed] [removed] <!-- function initAd() { document.all.AdLayer.style.posTop = -200; //设置onLoad事件激发以后,广告层相对于固定后的y方向位置 document.all.AdLayer.style.visibility = 'visible'//设置层为可见 MoveLayer('AdLayer');//调用函数MoveLayer() } function MoveLayer(layerName) { var x = 0;//浮动广告层固定于浏览器的x方向位置 var y = 300;//浮动广告层固定于浏览器的y方向位置 var diff = (document.body.scrollTop + y - document.all.AdLayer.style.posTop)*.40; var y = document.body.scrollTop + y - diff; eval("document.all." + layerName + ".style.posTop = y"); eval("document.all." + layerName + ".style.posright = x");//移动广告层 setTimeout("MoveLayer('AdLayer');", 0);//设置20毫秒后再调用函数MoveLayer() } //--> [removed] <!--下面为一个ID为AdLayer的层(如ID名不为AdLayer, 上面MoveLayer()内的AdLayer也要作相应修改),包括一张带链接的图片--> 本人文学网站开通,欢迎大家赏脸光顾 漂浮广告代码 <div id="www_qpsh_com" 本人文学网站开通,欢迎大家赏脸光顾 [removed] var x = 50,y = 60 var xin = true, yin = true var step = 1 var delay = 10 var obj=document.getElementById("www_qpsh_com") function floatwww_qpsh_com() { var L=T=0 //by www.qpsh.com var R= document.body.clientWidth-obj.offsetWidth var B = document.body.clientHeight-obj.offsetHeight obj.style.left = x + document.body.scrollLeft obj.style.top = y + document.body.scrollTop x = x + step*(xin?1:-1) if (x R){ xin = false; x = R} y = y + step*(yin?1:-1) if (y B) { yin = false; y = B } } var itl= setInterval("floatwww_qpsh_com()", delay) obj.onmouseover=function(){cle
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李泽举

如对你有帮助,那我就没白写

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值