-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How set up offset dynamically? #361
Comments
I have same issue . Any idea @WickyNilliams ? |
I have found solution for me: adding setOffset method to trackScroll. function trackScroll(element, options, callback) {
...
return {
destroy: function() {
cancelAnimationFrame(rafId);
element.removeEventListener("scroll", handleScroll, eventOptions);
},
setOffset: function (newOffset) {
options.offset = newOffset;
}
};
} Should I prepare a pull request? |
I'd hold off on a PR for now @Marenek (appreciate the offer though!). I have some ideas, but I'll have a proper think about how best to achieve this. Will keep you posted. |
@WickyNilliams Any chance this could get implemented? |
Still seems an issue. The method mentioned in #257 works in version //old method worked up until Headroom 0.9.4
var hr = new Headroom(element);
hr.init();
window.addEventListener("resize", function(e) {
hr.offset = getOffsetValue();
}, false); |
Hot Fix no solution yet... /* Common
--------------------------------------------- */
let normalizeUpDown = function( t ) {
return ( Object( t ) === t ) ? t : { down: t, up: t };
};
let instance = new Headroom(
document.querySelector( '.headroom' ),
{
// options...
}
);
/* Use this if need to observe the
* Window resize.
--------------------------------------------- */
instance.init = function() {
this.offset = normalizeUpDown( this.elem.offsetHeight );
window.addEventListener(
'resize',
() => {
if ( ! this.initialised ) {
return;
}
this.initialised = false;
this.scrollTracker.destroy();
this.init();
},
{
once: true,
}
);
return Headroom.prototype.init.apply( this, arguments );
};
instance.init();
/* Use this if need to observe the
* Target resize.
--------------------------------------------- */
let observer = new ResizeObserver(
function() {
this.offset = normalizeUpDown( this.elem.offsetHeight );
if ( ! this.initialised ) {
if ( ! this.scrollTracker ) {
this.init();
}
return;
}
this.initialised = false;
this.scrollTracker.destroy();
this.init();
}
.bind( instance )
);
observer.observe( instance.elem ); |
I change offset dynamically to manage hiding header with Headroom 0.9.4.
I have tried update to version 0.10.4 to use new freeze method.
But offset setting doesn't work in this version. How can I set offset dynamically now?
The text was updated successfully, but these errors were encountered: