PDA

View Full Version : [RESOLVED] Mouse wheel forcing Java


Snakehill
07-03-2009, 02:57 AM
This is related to http://www.htmlforums.com/html-xhtml/t-scroll-wheel-in-no-scrolling-frame-117902.html#post706019 but since this question includes a different kind of coding I'd like to ask it over here.

Apparently Java can force scrolling to work over scrolling="no" html and so I was wondering if there is a script which enables the mouse wheel to work at the same frame ('mainFrame in this case). So far only Opera users are able to use their mouse wheel to scroll down when scrolling="no" which was meant to hide the ugly default and uncostumizable scrollbars.

http://leonie.vanrheden.com/en/ -> Photos

As you can see there are scroll buttons next to the frame. Even though the frame is set to scrolling="no" those scroll buttons work cross browser, so If there is a java mouse wheel event this should work over the no-scrolling html code automatically.

Hope anyone can help me out! It's not that it's extremely necessary but it certainly would be nice. Thanks!

Snakehill
07-03-2009, 05:46 AM
Never mind. Found it.

For those who are interested in it:

Place this in the iframe's <head>


<script type="text/javascript">
/** This is high-level function.
* It must react to delta being more/less than zero.
*/
function handle(delta) {
var d=delta*-10;
window.scrollBy(0,d);
}

/** 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);
/** 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>


By changing the right numbers you can increase/decrease the scroll speed. F.i.:

if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;

...

/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail/3

Changing the 120 and the 3 to smaller numbers makes the scroll speed will increase. By making the number bigger the speed will decrease.