美文网首页
es6飘窗效果

es6飘窗效果

作者: 如此行走 | 来源:发表于2020-04-16 20:21 被阅读0次
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>es6飘窗功能</title>
    <style type="text/css">
      * {
        margin: 0px;
        padding: 0px;
      }

      #ad {
        position: absolute;
        left: 0px;
        top: 0px;
        z-index: 1000;
      }
      #ad a.adclose {
        cursor: pointer;
        position: absolute;
        right: 0px;
        top: 0px;
        color: black;
        padding: 0 6px;
        background-color: #c7cfda;
      }
    </style>
  </head>
  <body>
    <div id="ad">
      <a class="adclose" onclick="hidead()">×</a>
      <a href="http://www.baidu.com" target="_blank"
        ><img src="time.jpg" width="150" height="150"
      /></a>
    </div>
    <script>
      class Flutter {
        constructor() {
          this.ad = document.querySelector('#ad')
          this.close = document.querySelector('.adclose')
          // 定义横纵坐标
          this.x = 0
          this.y = 0
          // 设置初始速度
          this.xv = 1
          this.yv = 1
          this.mytime = null
          this.init()
        }
        init() {
          // 定时器调用
          this.mytime = setInterval(() => {
            this.move()
          }, 40)
          // ad绑定鼠标悬停事件
          this.ad.onmouseover = () => {
            // 清除定时器
            clearInterval(this.mytime)
          }
          // 鼠标离开,重新触发定时器
          this.ad.onmouseout = () => {
            this.mytime = setInterval(() => {
              this.move()
            }, 40)
          }
          this.close.onclick = () => {
            this.hidead()
          }
        }
        move() {
          if (this.x < 0 || this.x > window.innerWidth - this.ad.offsetWidth) {
            this.xv = -this.xv
          }

          if (
            this.y < 0 ||
            this.y > window.innerHeight - this.ad.offsetHeight - 1
          ) {
            this.yv = -this.yv
          }
          this.x += this.xv
          this.y += this.yv
          // 将xy坐标值赋予img css样式中的left与top
          this.ad.style.left = this.x + 'px'
          this.ad.style.top = this.y + 'px'
        }
        hidead() {
          document.body.removeChild(this.ad)
        }
      }
      new Flutter()
    </script>
  </body>
</html>

相关文章

  • es6飘窗效果

  • 2020-05-04

    飘窗可以怎么改造设计 真飘窗是在建筑外的,透气效果好;假飘窗是在家里的。 真飘窗是赠送的面积,而假飘窗讲白了面积就...

  • 飘窗效果图

    在合肥有一套房子,装修是一件很让人烦人的事。关于空间的每一个区域一定要合理的利用好,对于家里的飘窗怎样设计既美观又...

  • 修嗒嗒分享飘窗效果图欣赏 2019飘窗流行这样设计

    修嗒嗒分享飘窗效果图欣赏 2019飘窗流行这样设计。飘窗给人的第一感觉是浪漫,想象一下,温暖的午后,拿上一本书籍,...

  • 飘窗

    漂泊在外乡城市的人都是没有白天黑夜的,醒了便是天,睡了便是夜。 最初搬到这所新公寓,飘窗上面落满了灰尘,擦了许久才...

  • 飘窗

    对于刘心武,之前仅仅停留在红学大家的印象上。如今这一本《飘窗》更显其批判讽刺的文学功底。 庞奇一年前离开那条街时,...

  • 飘窗

    隐匿在卧室窗帘背后 小小的角落 敞亮,私密,偶尔孤单 随随便便就落满了灰 可是当喧嚣远去,它是我的整个天地 趴一整...

  • 飘窗

    三月的午后 暖暖的阳光隔着窗帘斜下来 像一串摇曳的风铃 随风舞动 美妙的旋律柔和地响起 ...

  • 飘窗

    飘窗一个安静的地方 在客厅 在厨房 在阳台 似乎都有需要忙碌的事情 飘窗上放上一个沙发椅 似乎就是另一个空间了 夹...

  • 飘窗

    新买的房子有一个飘窗,因为是中间户,所以飘窗只是南向的。 装修的时候,也没仔细考虑,只是铺了个仿大理石的台面,后来...

网友评论

      本文标题:es6飘窗效果

      本文链接:https://www.haomeiwen.com/subject/ojacmhtx.html