我正在尝试创建一个滚动动作,我想在其中切换.clone类及其转换。它在Chrome中运行正常,但它无法在Firefox上运行。 有人能帮助我吗?
CSS:
header {
display: none;
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
padding: 20px;
box-sizing: border-box;
font-size: 20px;
color: white;
}
header.clone {
display: block;
position: fixed;
top: -65px;
left: 0;
right: 0;
z-index: 999;
transition: 0.2s top cubic-bezier(.3, .73, .3, .74);
-webkit-transition: 0.2s top cubic-bezier(.3, .73, .3, .74);
-moz-transition: 0.2s top cubic-bezier(.3, .73, .3, .74);
-o-transition: 0.2s top cubic-bezier(.3, .73, .3, .74);
-ms-transition: 0.2s top cubic-bezier(.3, .73, .3, .74);
background: #3E3E3E;
}
JQuery的:
$(document).ready(function() {
var $header = $("header");
$clone = $header.before($header.clone().addClass("clone"));
$(document).on("scroll", function() {
var fromTop = $("body").scrollTop();
$("body").toggleClass("down",(fromTop > 800));
});
});
答案 0 :(得分:3)
更改您的代码,以便更好地支持跨浏览器滚动。使用window
代替¨body¨
...
$(document).on("scroll", function() {
var fromTop = $(window).scrollTop();
// Rest of code
});