hypeDocument.scrollToSelector
As this thread is mighty old, I added a new variation on the topic. This version supports callbacks and any selector as a target. It is written as an extension and based on a teeny tiny vanilla JS library (1.9kb) called window.smoothScroll
and has no other dependencies (like that bloated jQuery).
Hype Extension Code (What is an extension? Learn more about the extension project …)
/**
* hypeDocument.scrollToSelector 1.0
* @param {String} selector
* @param {Number} duration in seconds
* @param {Function} callback function when done
* @param {HTMLElement} scroll context
* @requires window.smoothScroll
*/
hypeDocument.scrollToSelector = function(selector, duration, callback, context) {
var target = document.querySelector(selector);
if (target instanceof HTMLElement){
window.smoothScroll(target, duration*1000 , callback, context);
}
}
Hype-file for demonstration
hypeDocument.scrollToSelector.hype.zip
Updates:
1.0 Initial release with simple example
PS: Love the Cheshire Cat grinning Alice (in wonderland) Lieutier has going! I could say it feels somewhat familiar