【发布时间】:2019-08-11 08:43:12
【问题描述】:
我在包装元素中有一个带有线性渐变的页面。
这是 HTML:
<body>
<div id="wrapper">
<div></div>
<div></div>
<div></div>
</div>
</body>
CSS 是:
#wrapper {
position: relative;
top: 0;
bottom: 0;
width: 100%;
z-index: -1;
background: -webkit-linear-gradient(rgba(0, 0,0,1) 0%, rgba(30,30,30,1) 60%, rgba(180,180,180,1) 100%); /* Safari 5.1 - 6.0 */
background: -o-linear-gradient(rgba(0, 0,0,1) 0%, rgba(30,30,30,1) 60%, rgba(180,180,180,1) 100%); /* Opera 11.1 - 12.0 */
background: -moz-linear-gradient(rgba(0, 0,0,1) 0%, rgba(30,30,30,1) 60%, rgba(180,180,180,1) 100%); /* Firefox 3.6 - 15 */
background: linear-gradient(rgba(0, 0,0,1) 0%, rgba(30,30,30,1) 60%, rgba(180,180,180,1) 100%);
padding-bottom: 1px;
}
渐变本身就可以显示。但是,我想在向下滚动页面时使用 js/jquery 来更改渐变。我认为当前的 js 代码目前没有任何影响。我该如何解决?谢谢。
$(window).scroll(function(){
var topDis = $(window).scrollTop();
$("#wrapper").css("background", "linear-gradient(rgba(0, 0, 0, 1) 0%, rgba(30,30,30,1) " + (60 - topDis/100) + "%, rgba(180,180,180,1) 100%);");
$("#wrapper").css("background", "-webkit-linear-gradient(rgba(0, 0, 0, 1) 0%, rgba(30,30,30,1) " + (60 - topDis/100) + "%, rgba(180,180,180,1) 100%);")
});
【问题讨论】:
标签: javascript jquery html css gradient