限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

javascript多层级DIV沉浸式滚动缩放动画特效代码

所属分类: 网页特效-动画效果    2023-12-01 09:27:12

javascript多层级DIV沉浸式滚动缩放动画特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript多层级DIV沉浸式滚动缩放动画特效代码(共3个文件)

    • index.html

使用方法

const farsight = (() => {
  const selectors = {
    anchor: 'a[href^="#"]',
    depth: '.scene__depth',
    layers: '.layer',
    menu: '.menu',
    scene: '.scene',
  };

  const classes = {
    activeMenu: 'menu__item--active',
  };

  const distance = 500;

  /**
   * DO NOT EDIT BELOW. THE SKY WILL FALL.
   */
  const layers = [...document.querySelectorAll(selectors.layers)];

  const current = {
    layer: 0,
    progress: 0,
    menu: ''
  };

  let windowDepth = '';

  const setActive = () => {
    // update menu
    let position = current.layer + Math.round(current.progress);

    if (position !== current.menu) {
      const menuContainer = document.querySelector(selectors.menu);
      let menuActive = menuContainer.querySelector(`.${classes.activeMenu}`);
      let layer = document.querySelector(`.layer[data-depth="${position * distance}"]`);

      if (typeof menuActive !== 'undefined' && menuActive !== null) {
        menuActive.classList.remove(classes.activeMenu);
      }

      menuContainer.querySelector(`a[href="#${layer.getAttribute('id')}"]`).classList.add(classes.activeMenu);

      current.menu = position;
    }
  };

  const zoomScene = () => {
    let scroll = this.scrollY;

    // get scroll, cap within bounds
    scroll = scroll >= 0 ? (scroll <= windowDepth ? scroll : windowDepth) : 0; // set currents current.layer = (scroll / distance) | 0; current.progress = (scroll - (current.layer * distance)) / distance; current.overallProgress = (scroll / (distance * layers)); const scene = document.querySelector(selectors.scene); // adjust scene setZPosition(scene, scroll); // update menu and layer setActive(); }; const setZPosition = (element, z) => {
    element.style.transform = `translate3d(0, 0, ${z}px)`;
  };

  const setDepth = () => {
    const depth = document.querySelector(selectors.depth);

    windowDepth = (distance * (layers.length - 1)) + document.body.clientHeight;
    depth.style.height = `${windowDepth}px`;
  };

  const scrollToLayer = (target) => {
    console.log(target);
    TweenLite.to(window, 1, {
      scrollTo: target,
    });
  };

  return {
    render: function() {
      // set environment depth
      setDepth();

      // set layer z position
      layers.map(layer => {
        const layerDepth = layer.getAttribute('data-depth');

        setZPosition(layer, layerDepth * -1);
      });

      // set initial position
      zoomScene();

      // zooming
      var throttledZoom = _.throttle(zoomScene, 25);

      window.addEventListener('scroll', throttledZoom);

      // resize
      window.addEventListener('resize', setDepth);

      // anchors
      const anchors = [...document.querySelectorAll(selectors.anchor)];

      anchors.map(anchor => {
        anchor.addEventListener('click', function (e) {
          e.preventDefault();
          const targetAnchor = this.getAttribute('href');
          const target = document.querySelector(targetAnchor).getAttribute('data-depth');

          scrollToLayer(target);
        });
      });
    }
  }
})();

farsight.render();

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

CSS3带背景动画视差效果的报价单列表特效

一款蓝色风格的网站制作报价单动画特效,共三列三个不同的方案套餐,每个套餐都包括一个功能列表、一个服务价格和一个点击按钮。采用了SVG、渐变背景动画和视差效果。
  动画效果
 8250  0

jquery轻量级自定义添加移除加载动画特效代码

一个超小的加载动画插件,可自由添加显示加载动画,还可移除隐藏的loading特效。
  动画效果
 2378  0

javascript鼠标跟随五彩缤纷烟花动画特效

基于SVG和VanillaJS创建的Sparkle Motion效果。鼠标移动时产生了五颜六色的烟花特效。鼠标点击、移动或触摸手势后会产生烟花特效。
  动画效果
 1387  0

canvas画布点阵动画特效代码

一款可自定义的像素画动画效果,支持自定义设置间隔时间(毫秒)、乱码输出,集成了7款不同的图标,点击后可动画生成,非常有趣!
  动画效果
 6133  0

评论数(1) 回复有机会获得K币 用户协议

    铁头de科技0
    2024-01-17 15:46:43
    感觉有点进入了四维空间啊,大家有没有觉得😵
    回复
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论