页面局部上浮动画配合滚轮实现

 float.css

.show-float {
  opacity: 0.5;
  position:relative;
  margin-top: 80px;
}

.show-animate {
  animation: showanimate 2s forwards;
}

@keyframes showanimate {
  100% {
    opacity: 1;
    /* margin-top: 0px; */
  }
  from {bottom:0px;}
  to {bottom:50px;}
}

.hide-animate {
  /* margin-top: 0px; */
  opacity: 1;
  margin-top: 80px;
  /* animation: hideanimate 2s forwards; */
}

@keyframes hideanimate {
  100% {
    opacity: 0.5;
    margin-top: 50px;
  }
}

float.js 

(function (global) {
  "use strict";
  let w_height = window.innerHeight;
  $(document).on("mousewheel DOMMouseScroll", onMouseScroll);
  function onMouseScroll(e) {
    e.preventDefault();
    var wheel = e.originalEvent.wheelDelta || -e.originalEvent.detail;
    var delta = Math.max(-1, Math.min(1, wheel));
    let t = document.documentElement.scrollTop;
    let dis_height_t = w_height + t;

    if (delta < 0) {
      //向下滚动
      $(".show-float").each(function (index, element) {
        let t_h = $(element).offset().top;
        if (t_h < dis_height_t + w_height / 4) {
          // debugger;
          $(element).removeClass("hide-animate");
          $(element).addClass("show-animate");
        }
      });
    } else {
      //向上滚动
      $(".show-float").each(function (index, element) {
        let t_h = $(element).offset().top;
        if (t_h > dis_height_t - w_height / 2) {
          $(element).removeClass("show-animate");
          $(element).addClass("hide-animate");
        }
      });
    }
  }
})(this);

引入资源后,添加'show-float' class

<div class="product-section product-features show-float" id="huodong"></div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值