veu 漂浮广告 (鼠标触摸可悬停)

<template>

  <div>

  <div id="thediv" ref="thediv" @mouseover="clearFdAd" @mouseout="starFdAd">我是浮动广告</div>

  </div>

  </template>

  <script>

var interval

  export default {

  data() {

    return {

      xPos:300,

      yPos:200,

      step:1,

      delay:8,

      height:0,

      Hoffset:0,

      Woffset:0,

      yon:0,

      xon:0,

      pause:true,

    };

  },

  mounted() {

    interval=setInterval(this.changePos,10)

  },

  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";

          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,10)

    },

  }

};

</script>

#thediv {

  z-index: 100;

  position: absolute;

  top: 43px;

  left: 2px;

  height: 100px;

  width: 100px;

  background-color: red;

}

————————————————

原文链接:https://blog.csdn.net/h5_since/article/details/109350534

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • (一)知识点 1.1属性 element.className element对象的class字符串数组,每个字符...
    Zvit阅读 469评论 0 0
  • /*! jQuery JavaScript Library v1.4.2 http://jquery.com/ C...
    ssttIsme阅读 1,979评论 2 0
  • 姓名:岳沁 学号:17101223458 转载自:http://www.jianshu.com/p/91ae072...
    丘之心阅读 3,285评论 0 0
  • js的组成部分 前面学习的部分是ECMAScript部分,都是基础语法部分。基础语法只是规定的代码如何写,并不能实...
    新生勿扰阅读 333评论 0 0
  • 什么是JavaScript? 1. JavaScript 是一种客户端脚本语言(脚本语言是一种轻量级的编程语言)。...
    ximoos阅读 446评论 0 6