滚动视差-03【模仿小米页面效果】

滚动视差-03【模仿小米×华为页面效果】

小米官方网站效果示例:https://www.mi.com/mi9pro【第四屏】

华为官方网站效果示例:https://consumer.huawei.com/cn/phones/nova5

以下是运用的插件【skrollr.js】参考网站

官方网站:http://prinzhorn.github.io/skrollr/

Github地址:https://github.com/Prinzhorn/skrollr

详细教程:https://www.jianshu.com/p/ffe6eb46bb8f(来自简书)

本案例是滚动视差最终的一个效果,也是自己接触滚动视差以来最想要的一个效果。话不多说,直接上代码。

一、搭建基本页面

<div id="easing_wrapper" data-0="display:none;"
     data-1000="display:block;"
     data-2900="background:rgba(0, 0, 0, 0);color[swing]:rgb(0,0,0);"
     data-3900="background:rgba(0,0,0,1);color:rgb(255,255,255);"
     data-6000="top:0%;" data-12000="top:-100%;">
    <div id="easing" data-2900="left:100%" data-3500="left:25%;">
        <h2>easing?</h2>
        <p>sure.</p>
        <p>let me dim the <span data-3900="" data-4900="color[swing]:rgb(0,0,0);" data-5900="color:rgb(255,255,0);">lights</span> for this one...</p>
        <p data-5900="opacity:0;font-size:100%;" data-6500="opacity:1;font-size:150%;">you can set easings for each property and define own easing functions</p>
    </div>

    <div class="drop" data-3500="left:15%;bottom:100%;" data-5500="bottom:0%;">linear</div>
    <div class="drop" data-3500="left:25%;bottom[quadratic]:100%;" data-5500="bottom:0%;">quadratic</div>
    <div class="drop" data-3500="left:35%;bottom[cubic]:100%;" data-5500="bottom:0%;">cubic</div>
    <div class="drop" data-3500="left:45%;bottom[swing]:100%;" data-5500="bottom:0%;">swing</div>
    <div class="drop" data-3500="left:55%;bottom[WTF]:100%;" data-5500="bottom:0%;">WTF</div>
    <div class="drop" data-3500="left:65%;bottom[inverted]:100%;" data-5500="bottom:0%;">inverted</div>
    <div class="drop" data-3500="left:75%;bottom[bounce]:100%;" data-5500="bottom:0%;">bounce</div>
</div>

二、添加css样式

  .skrollable {
            position:fixed;
            z-index:100;
        }
        .skrollable .skrollable .skrollable {
            position:static;
        }
        .skrollr-mobile .skrollable {
            position:absolute;
        }

        .skrollable .skrollable {
            position:absolute;
        }

        html, body {
            width:100%;
            height:100%;
            padding:0;
            margin:0;
            overflow-x:hidden;
        }
        body {
            background: #eeeeee;
            background: -webkit-linear-gradient(top, #eeeeee, #cccccc 100%);
            background: -moz-linear-gradient(top, #eeeeee, #cccccc 100%);
            background: -o-linear-gradient(top, #eeeeee, #cccccc 100%);
            background: -ms-linear-gradient(top, #eeeeee, #cccccc 100%);
            background: linear-gradient(top, #eeeeee, #cccccc 100%);
            background-attachment:fixed;
        }
        #easing_wrapper {
            width:100%;
            height:100%;
        }
        #easing {
            top:10%;
            width:50%;
            z-index:101;
        }

        .drop {
            background:#09f;
            font-weight:bold;
            padding:1em;
        }

三、添加js效果

<script src="js/skrollr.min.js"></script>
<script>
    var s = skrollr.init({
        edgeStrategy: 'set',
        easing: {
            WTF: Math.random,
            inverted: function(p) {
                return 1-p;
            }
        }
    });
</script>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,页面滚动视差是一种常见的网页设计效果,可以为网页增添立体感和动态效果。实现页面滚动视差的方法是利用CSS和JavaScript,具体步骤如下: 1. 创建一个HTML文件,包含网页需要的内容和结构。 2. 在CSS中设置网页背景图片,并设置其position为fixed,固定不动。 3. 在CSS中设置其他元素的背景图片,和背景图片的位置。将元素的position设置为relative,使其相对于父元素定位。 4. 使用JavaScript监听网页滚动事件。当网页滚动时,根据滚动距离计算元素需要移动的距离,然后使用CSS中的transform属性实现元素的移动。 5. 根据需要,可以设置元素的动画效果,如缓动动画等。 下面是一个简单的示例代码,供您参考: HTML代码: ```html <div class="parallax"> <div class="parallax-bg"></div> <div class="parallax-content"> <h1>这是一个滚动视差网页</h1> <p>滚动鼠标,体验视差效果</p> </div> </div> ``` CSS代码: ```css .parallax { height: 100vh; position: relative; overflow: hidden; } .parallax-bg { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-image: url('bg.jpg'); background-size: cover; background-position: center; z-index: -1; } .parallax-content { position: relative; text-align: center; padding: 50px; } ``` JavaScript代码: ```javascript window.addEventListener('scroll', function() { const parallax = document.querySelector('.parallax'); const parallaxContent = document.querySelector('.parallax-content'); const parallaxBg = document.querySelector('.parallax-bg'); let scrollPosition = window.pageYOffset; parallax.style.transform = `translateY(${scrollPosition * 0.5}px)`; parallaxContent.style.transform = `translateY(${scrollPosition * -0.2}px)`; parallaxBg.style.transform = `translateY(${scrollPosition * 0.8}px)`; }); ``` 以上代码实现了一个简单的滚动视差网页,当用户滚动页面时,背景图片和文本内容会以不同的速度移动,产生立体感和动态效果。您可以根据需要调整元素的移动速度和距离,以实现更加丰富的视差效果

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值