MDN告诉我如何创建自定义事件(我没搞清楚)
var event = new Event('build');
// Listen for the event.
elem.addEventListener('build', function (e) { ... }, false);
// Dispatch the event.
elem.dispatchEvent(event);
而且我也知道如何检测鼠标滚动...
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);
}
但我不知道如何将这两者混合并创建一个自定义事件,所以我可以有这样的事情:
window.addEventListener('scrollUp', sUpFunction);
window.addEventListener('scrollDown', sDownFunction);
感谢你们。