FullPage DEMO

fullpage demo

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #container {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: 99999;
      overflow: hidden;
    }

    .slide1 {
      background-color: rgb(27, 188, 155);
    }

    .slide2 {
      background-color: rgb(255, 153, 0);
    }

    .slide3 {
      background-color: rgb(123, 170, 190);
    }
  </style>

</head>

<body>
  <div id="container">
    <div id="scrollContainer">
      <div style="height: 0;" class="slide slide1"></div>
      <div style="height: 0;" class="slide slide2"></div>
      <div style="height: 0;" class="slide slide3"></div>
    </div>
  </div>
  <script>
    let height = document.getElementById("container").offsetHeight;
    let slides = document.getElementsByClassName("slide");
    for (let ele of slides) {
      if (ele) {
        ele.style.height = `${height}px`;
      }
    }
    let scrollEle = document.getElementById("scrollContainer");

    let page = {
      timeWait: 1000,
      duration: 850,
      current: 1,
      len: 3,
      isScrolling: false,
      next: function () {
        if ((this.current + 1) <= this.len) {
          this.current += 1;
          this.move(this.current);
        }
      },
      pre: function () {
        if (this.current - 1 > 0) {
          this.current -= 1;
          this.move(this.current);
        }
      },
      move: function (index) {
        this.isScrolling = true;
        let di = -(index - 1) * height + 'px';
        // page.start = +new Date();
        scrollEle.style.cssText= `transition: all ease ${this.duration / 1000}s;transform: translateY(${di})`
        // $scroll.css('transform', 'translateY(' + di + ')');
        setTimeout(() => {
          this.isScrolling = false;
        }, this.timeWait);
      }
    };

    // 滚动事件绑定
    function bindMouseWheel(page) {
      let type = 'mousewheel';
      let deltaY = 0;

      function mouseWheelHandle(event) {
        // console.log("滚轮事件");
        if (page.isScrolling) { // 加锁部分
          return false;
        }
        let e = event.originalEvent || event;
        console.log("e:{}", e.deltaY);

        deltaY = e.deltaY;
        if (deltaY > 0) {
          page.next();
        } else if (deltaY < 0) {
          page.pre();
        }
      }
      document.addEventListener('mousewheel', mouseWheelHandle, true);
      // $(document).on('mousewheel', mouseWheelHandle);
    }

    bindMouseWheel(page);
  </script>
</body>
</html>

兼容性没有测试

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值