The MDN told me how to create a custom event (which I didn't get it well)
var event = new Event('build');
// Listen for the event.
elem.addEventListener('build', function (e) { ... }, false);
// Dispatch the event.
elem.dispatchEvent(event);
and I know how to detect mouse scroll as well...
var doScroll = function (e) {
// cross-browser wheel delta
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
// Do something with `delta`
document.body.innerHTML = delta;
e.preventDefault();
};
if (window.addEventListener) {
window.addEventListener("mousewheel", doScroll, false);
window.addEventListener("DOMMouseScroll", doScroll, false);
} else {
window.attachEvent("onmousewheel", doScroll);
}
but I don't know how to mix these two with each other and create a custom event so I can have something like this:
window.addEventListener('scrollUp', sUpFunction);
window.addEventListener('scrollDown', sDownFunction);
Thank you guys.
First I would use the "wheel" event instead of the non-standardrized "mousewheel" event.
I created a simple implementation of a scrollUp and scrollDown custom events dispatch.
EDIT
I have a added the IE polyfill for the CustomEvent in order to support IE as well