我的网站上有一个粘性块。它有3个条件:
THE PLOBLEM
在Android Chrome功能上工作不正确:当块在页脚之前被紧固(我们滚动到文档的底部)时,我们滚动到顶部(块变粘),文档滚动到文档的中间(whaaat)。这就像它相对于main
块中的某些块的位置。为什么会这样?在PC上,Chrome一切都很好。
代码(buttonsBlock
是粘性的):
var buttonsPrimaryPosition = $(".buttons-320").offset().top; //position of block on load
function makeButtonsSticky() {
var buttonsBlock = $(".buttons-320");
var buttonsPosition = buttonsBlock.offset().top + 75; // bottom side of the block position, 75 height of the block
var totalHeight = $(window).scrollTop() + $(window).height(); //bottom side of the viewport coordinate
var footerTop = $(document).height() - $(".footer").height(); //top side of footer coordinate
if ( totalHeight >= buttonsPrimaryPosition + 75 && totalHeight < warrantyTop ) {
buttonsBlock.appendTo($(".header"));
buttonsBlock.addClass("buttons-320-fixed");
buttonsBlock.removeClass("buttons-320-bottom");
} else if ( totalHeight >= footerTop ) {
$(".footer").before(buttonsBlock);
buttonsBlock.removeClass("buttons-320-fixed");
buttonsBlock.addClass("buttons-320-bottom");
} else {
buttonsBlock.appendTo($(".header"));
buttonsBlock.removeClass("buttons-320-fixed");
buttonsBlock.removeClass("buttons-320-bottom");
};
};
$(window).scroll(function() {
makeButtonsSticky();
});
CSS
.buttons-320 {
background: #2693c5 url('img/buttons-border.png') no-repeat center;
margin-top: 25px;
}
.buttons-320-fixed {
position: fixed;
bottom: 0;
width: 100%;
z-index: 150;
}
.buttons-320-bottom {
margin-top: 0;
}
HTML
<header class="header">
<div class="button-320"><>
</header >
<main></main>
<footer></footer>
答案 0 :(得分:0)
答案是添加head
以下短语:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">