粘性/固定标头在 Firefox 和 Android 中不起作用
Sticky/fixed header doesn't work in Firefox and Android
我一直在研究一个标题,当用户滚动到一定数量的像素时固定。
它适用于Chrome,但在Firefox和Android默认浏览器上根本不起作用。我怀疑这与scrollTop
有关,但我不确定是什么。
这是我的演示和代码:
http://jsfiddle.net/xaliber/Y5xeZ/1/
$(window).scroll(function() {
var top = $(window).scrollTop();
var floatheader = $('#telunjuk-category').height()
+ parseInt($('#telunjuk-category').css('padding'))
+ parseInt($('#telunjuk-category').css('borderWidth')); // height of <header>
var whitebarandsearchbar = 68 + $('.ui-listview-filter.ui-bar-c').height()
+ parseInt($('.ui-listview-filter.ui-bar-c').css('padding'))
+ parseInt($('.ui-listview-filter.ui-bar-c').css('borderWidth'));
if (top > floatheader) // height of float header
$(function() {
$('#categorypage #telunjuk-titlebar').addClass('stick');
$('#categorypage .ui-listview-filter.ui-bar-c ').addClass('stick');
$('#categorypage').css("padding-top", whitebarandsearchbar);
})
else {
$('#categorypage').removeAttr('style');
$('#categorypage .ui-listview-filter.ui-bar-c').removeClass('stick');
$('#categorypage #telunjuk-titlebar').removeClass('stick');
}
});
它使用多个变量,因为<header>
(存储在floatheader
中)会随着不同的屏幕尺寸而改变高度。搜索表单(与#telunjuk-titlebar
一起存储在whitebarandsearchbar
中)也是如此。
我试图按照这个答案的建议将$(window).scrollTop()
更改为$(document).scrollTop()
。我也尝试了这篇文章中建议的修复程序。但它仍然不起作用。
有什么帮助吗?
#telunjuk-category
既没有padding
的CSS值,也没有borderWidth
的CSS值。所以$('#telunjuk-category').css('padding')
的返回值是 – 无。虽然Chrome只是将一个空值解析为0
,但Firefox显然返回NaN
。这就是为什么它在当前版本中不起作用的原因。
作为一种解决方案,您最好放弃为jQuery的outerHeight()
函数自定义添加所有CSS值。这个函数已经包括所有的填充和边框(如果你愿意,甚至可以包括边距)。
所以
var floatheader = $('#telunjuk-category').height()
+ parseInt($('#telunjuk-category').css('padding'))
+ parseInt($('#telunjuk-category').css('borderWidth'));
成为
var floatheader = $('#telunjuk-category').outerHeight();
whitebarandsearchbar
也应该这样做。
注意:此解决方案在Firefox中确实有效,我无法在Android上进行测试,但是在Android上position:fixed;
存在一些一般问题:http://caniuse.com/css-fixed
- 如何在javascript中获取Android Firefox中的menuID
- Firefox for Android扩展:如何在每次页面加载时触发事件
- Firefox for Android - 地址栏内容重叠.有没有解决方案
- Jquery.Load不适用于android浏览器,但适用于同一设备上的Firefox移动浏览器
- 在Firefox for Android的onload事件中,window.innerWidth的值错误
- 粘性/固定标头在 Firefox 和 Android 中不起作用
- FRAMEBUFFER_INCOMPLETE_ATTACHMENT只发生在带有Firefox的Android上
- 地理编码器仅适用于chrome,不适用于Firefox / IE / android
- 引导程序中的全局变量.js在 Firefox for Android 扩展中
- 通过usb调试android手机上的Firefox扩展
- Javascript在Firefox for Android中随机返回不一致的高度
- 如何在Firefox Mobile (Android, Fennec 7.0.1)中检测触摸支持
- 下拉开关不能正常工作为Firefox-Android
- Three.js Camera Orientation in Firefox for Android
- WebSocket在Firefox中支持Android插件吗?
- 是否可以从Firefox for android插件中获取网络类型?
- Android版Firefox中设备方向代码的问题
- JavaScript:跟踪Android上Firefox的选择变化
- 如何在Firefox for Android中检测Android'
- 如何在android上的firefox插件中使用沙盒回调