美文网首页
全屏滚动

全屏滚动

作者: LilyLaw | 来源:发表于2020-03-28 10:53 被阅读0次

做了一个简单的全屏滚动,代码如下,比较简单

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            html,body{
                overflow: hidden;
            }
            html, body, #container{
                height: 100%;
            }
            #container{
                position: relative;
            }
            .sections{
                position: absolute;
                top: 0;
                width: 100%;
                transition: top .5s ease-in;
            }
            .section{
                background-size: 100% auto;
                background-repeat: no-repeat;
                background-position: center center;
            }
            .section:nth-child(1){
                background-image: url("http://seopic.699pic.com/photo/50156/2840.jpg_wh1200.jpg");
            }
            .section:nth-child(2){
                background-image: url("http://seopic.699pic.com/photo/50148/0957.jpg_wh1200.jpg");
            }
            .section:nth-child(3){
                background-image: url("http://seopic.699pic.com/photo/50146/0835.jpg_wh1200.jpg");
            }
            .section:nth-child(4){
                background-image: url("http://seopic.699pic.com/photo/50021/1012.jpg_wh1200.jpg");
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div class="sections">
                <div class="section"></div>
                <div class="section"></div>
                <div class="section"></div>
                <div class="section"></div>
            </div>
        </div>
        
        <script type="text/javascript">
            let wh = parseInt(window.innerHeight),
                    ele = document.getElementsByClassName('sections')[0],
                    eachSection = document.getElementsByClassName('section'),
                    flag = true;
            renderHeight();
            
            function renderHeight(){
                ele.style.height = wh*eachSection.length +"px";
                for(let i=0;i<eachSection.length;i++){
                    eachSection[i].style.height = wh+"px";
                }
            }
            
            document.addEventListener('mousewheel',function(e){
                if(flag){
                    let nowt = Math.abs(parseInt( getComputedStyle(ele).top));
                    if(e.deltaY > 0 && nowt < wh*(eachSection.length - 1)){ //向下滑动
                        ele.style.top = -(nowt+wh)+"px";
                    }else if(e.deltaY < 0 && nowt > 0){ // 向上滑动
                        ele.style.top = -nowt+wh+"px";
                    }
                    flag = false;
                    
                    setTimeout(function(){
                        flag = true;
                    },500);
                }
                
            });
        </script>
    </body>
</html>

相关文章

  • 防酷狗的滚动监听,网站实用案例【附有美女】

    老司机们,请全屏观看 滚动监听 滚动 blockquot...

  • 全屏滚动

    jquery.fullPage.js全屏滚动插件教程演示

  • 全屏滚动

    公众号等场所使用全屏滚动页面的一种实现思路 页面的动画变换可以使用transition: all 1s; 设置为a...

  • 全屏滚动

    做了一个简单的全屏滚动,代码如下,比较简单

  • jquery全屏滚动插件fullpage中文文档

    今天给大家带来一款Jquery全屏滚动插件fullpage,这款插件可以非常方便快速的做一个全屏滚动高大上的网站,...

  • iOS10下的全屏布局及渐变图层

    全屏布局 什么叫做全屏幕布局: 就是在一个屏幕上的布局,不想tableView可以滚动,这个不可以滚动 如何布局:...

  • swiper制作全屏滚动首页

    公司需要制作国外官网,各种花里胡哨的动效,并且要求全屏滚动 开始编写首页前,需要先将全屏滚动弄好,我对比swipe...

  • fullpage框架

    jQuery的一个全屏jQuery全屏滚动插件fullPage.js。我们经常见到一些全屏的特绚丽页面,手指或者鼠...

  • contentInset偏移

    利用contentInset可以实现滚动偏移效果。 如图:tableView是全屏大小,滚动到最底会出现偏移。

  • 全屏滚动-fullPage

    全屏网站看起来很爽的样子先看iPhone的网站体验一哈,高端大气上档次今天使用jQuery插件fullPage.j...

网友评论

      本文标题:全屏滚动

      本文链接:https://www.haomeiwen.com/subject/swrruhtx.html