一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

h5页面背景图很长要有滚动条滑动效果实现代码

时间:2022-06-25 17:52:45 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下h5页面背景图很长要有滚动条滑动效果实现代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

背景图铺满页面,要求有滚动条可以滑动,思路是用js获取背景图片的高,在获取当前窗口的高,两者比较,当窗口的高小于背景图片的高,把窗口的高设置成背景颜色的高。反之就是窗口的高。


       




长背景图测试/title>
<style type="text/<a href=" http: target="_blank">css">
        //body里面的属性min-height是关键,网上说直接设置成100vh即可,如果不可以可以自己微调
    body{
        background:url(./images/download_bg.png) no-repeat;
        background-size:100%;
                //方案1
        min-height: 185vh;
                //方案2,本质等价于方案一,如果两个方案是同时开启,则会使用高度更小的那个,已测试
                //
    }
 
    #btn{
        margin-top: 150px;
        text-align: center;
    }  
     
</style>

 

这是网上的代码。

改动了下

body{
    background: -webkit-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: -o-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: -moz-linear-gradient(to bottom , #699eef, #8e92ef); 
    background: linear-gradient(to bottom , #699eef, #8e92ef);
  
}
.app {
    width: 100%;
    /*  */
    min-height: 120vh;
    /* position: fixed; */
    /* top: 0; */
    /* left: 0; */
    background: url('../../images/bg.jpg') no-repeat;
    background-size: 100% auto;
    
}

给body加了个跟图片颜色一样的背景色

热门栏目