Mousewheel event og pageX/Y i Firefox
HejHar en stykke JavaScript der fanger mousewheel evnts.
Det kommer her fra: http://adomas.org/javascript-mouse-wheel/
Det virker som det skal, men hvis jeg prøver at smide event.pageX eller pageY ud i FF2, for jeg helt forkerte værdiger. Virker fint i Opera9 og IE7.
Jeg kunne rigtigt godt tænke mig at det kom til at virke...
Har lavet et lille kode eksempel, så i selv kan prøve.
#######################################################
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>mousewheel test</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
/** This is high-level function.
* It must react to delta being more/less than zero.
*/
function handle(delta, x, y) {
alert(x + " x " + y);
}
/** Event handler for mouse wheel event.
*/
function wheel(event){
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
/** In Opera 9, delta differs in sign as compared to IE.
*/
if (window.opera)
delta = -delta;
} else if (event.detail) { /** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail/3;
}
/** If delta is nonzero, handle it.
* Basically, delta is now positive if wheel was scrolled up,
* and negative, if wheel was scrolled down.
*/
if (delta)
handle(delta, event.pageX, event.pageY);
/** Prevent default actions caused by mouse wheel.
* That might be ugly, but we handle scrolls somehow
* anyway, so don't bother here..
*/
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
/** Initialization code.
* If you use your own event management code, change it as required.
*/
if (window.addEventListener)
/** DOMMouseScroll is for mozilla. */
window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;
</script>
</body>
</html>
#######################################################