Mouse scroll wheel hack: update
So I was playing around with my solution, my little mouse wheel hack for processing.js, that I mentioned in my last post. I first was making sure I could get it to work in Firefox, Safari, Opera, and Chrome. It really wasn’t all that hard. I also wanted to jazz it up a bit, and use the mouse scroll for something more meaty. This is what I came up with.
In my last example, it was setup to work in all browsers, but it was only being called the Firefox way.
The problem was in this line:
addEventListener('DOMMouseScroll', wheel, false);
Firefox uses ‘DOMMouseScroll’, Opera, Chrome, and Safari use “mousewheel”
So, after some research, I changed the line to this:
addEventListener(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel", wheel, false);
What this is doing, is testing the navigator.userAgent for the word Firefox. Obviously, if you’re using Firefox, the word will exist in the same spot. There are other less reliable ways to do this, as I found in my researching of this problem. I usually lean towards the solutions that make the most sense to me (obviously :P). The rest of the line just loads the certain string inside a ?: conditional statement.
I’ll do some testing and cleaning tomorrow, and if I don’t find any bugs, I’ll flag it for peer-review.