我有一个网页,我在其中使用粘滞按钮仅在移动设备上使用
<div id="toBooking" class="bg-light d-lg-none d-xl-none">
<a class="btn_full" style="margin-bottom:0; background: #0072bc !important;" href="#"> <sup>$</sup> Book Now</a>
</div>
这是我拥有的
var pxBtShow = 500; // height on which the button will show
var scrollSpeed = 500; // how slow / fast you want the button to scroll to top.
$(window).scroll(function(){
if($(window).scrollTop() >= pxBtShow){
$("#toBooking").addClass('visible');
} else {
$("#toBooking").removeClass('visible');
}
});
$("#toBooking").click(function() {
$('html, body').animate({
scrollTop: $("#booking").offset().top
}, 1000);
});
和CSS
#toBooking {
position: fixed;
right: 0;
opacity: 0;
visibility: hidden;
bottom: 0px;
z-index: 999;
transition: 0.35s;
transform: scale(0.7);
width: 100%;
height: 46px;
background-color: rgba(0,0,0,.6);
opacity: 1;
transition: all 0.3s;
border-radius: 50%;
text-align: center;
font-size: 21px;
color: #fff;
cursor: pointer;
}
#toBooking.visible {
opacity: 1;
visibility: visible;
transform: scale(1);
}
#toBooking:after {
content: "\e899";
font-family: "fontello";
position: relative;
display: block;
top: 50%;
-webkit-transform: translateY(-55%);
transform: translateY(-55%);
}
当我单击按钮时,它将带我到预订表格。但是当我在表单上时,我想在表单高度期间隐藏该按钮。
我们该怎么做?
答案 0 :(得分:0)
您只需要添加更多逻辑,例如:
$(window).scroll(function () {
var windowScrollTop = $(window).scrollTop()
var $form = $('#form');
var formOffset = $form.offset();
if (
windowScrollTop >= pxBtShow &&
windowScrollTop < formOffset.top &&
windowScrollTop > formOffset.top + $form.height()
) {
$("#toBooking").addClass('visible');
} else {
$("#toBooking").removeClass('visible');
}
});