web视差滚动浏览 - 让页面看起来有纵深立体感

根据滚动页面的位置,控制页面元素的滚动差,使页面看起来有深度有纵深立体感。

放飞你的设计,让页面更具个性~~

下载:https://download.csdn.net/download/zhi_jie/11172152
JS代码:

/*
// ======视觉差滚屏效果 - 夕空 | 2019-5
scrollplay(元素,消失点) 消失点也就是原始坐标会和点
元素需要sc 时差属性
sc>0的值是超过滚动条速度的,反之sc<0的值是慢于滚动条速度。
------
html: <div class="scrollbox" sc="-0.5">示例</div>
JS: scrollplay($(".scrollbox"), $(window).height()*0.4);
*/
function scrollplay($target,$point){
    var point=$point || 300;
    $target.each(function(){
        $(this).data("top",$(this).offset().top);
    })
    document.onscroll = function(){
        var scrollTop = $(window).scrollTop();
        var fold = $(window).height() + scrollTop;
        scrollbox($target,fold,scrollTop,point);
    }
}
function scrollbox($target,fold,scrollTop,point){
    $target.each(function(){
        //从下方进入时 && 至顶部域内
        if ($(this).data("top")<fold && scrollTop < $(this).offset().top+$(this).height()) {
            var newY=($(this).data("top")-point-scrollTop)*$(this).attr('sc');
            $(this).css("transform","translateY("+newY+"px)");
        }
    })
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值