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

作者:袖梨 2022-06-25

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

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


       




长背景图测试/title>


 

这是网上的代码。

改动了下

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加了个跟图片颜色一样的背景色

相关文章

精彩推荐