在我的网站上我有一个相对位置的div,这个div有 bottom:0
和 width: 100%
当用户在页面上滚动时div会变为固定位置,同时底部0和宽度:100%(div从具体位置移动到页面底部) . 我用jQuery做这个,但我可以't apply a smooth transition. How could I do this? I tried with .animate() but doesn'工作 .
这是脚本
jQuery(function($){
$(window).scroll(function(){
let a = 350;
let pos = $(window).scrollTop();
if(pos > a) {
$("#button-presupuesto").addClass('isFixed');
}else{
$("#button-presupuesto").removeClass('isFixed');
}
});
});
和css:
.isFixed{
width: 100%;
position: fixed;
z-index: 999;
bottom: 0;
}
1 回答
您应将其位置设置为
fixed
并使用transition
与visibility
,opacity
使其平滑 .