根据屏幕大小,我需要在 Headroom.js 中有不同的偏移量。
Enquire.js 应该可以解决问题,但我无法让它正常工作。它在每次页面加载时只加载一个偏移设置,即使它在加载时是正确的,但是当我调整屏幕大小时它不会切换到另一个设置。
enquire.register("screen and (max-width: 48rem)", {
// REQUIRED
// Triggered when the media query transitions
// from *unmatched* to *matched*
match : function() {
Headroom.options = {
offset : 0, };
},
// OPTIONAL
// Triggered when the media query transitions
// from a *matched* to *unmatched*
unmatch : function() {
Headroom.options = {
offset : 137, };
},
// OPTIONAL
// Triggered once immediately upon registration of handler
setup : function() {
},
// OPTIONAL
// Defaults to false
// If true, defers execution of the setup function
// until the first media query is matched (still just once)
deferSetup : true
});