Mouse scroll wheel hack: update

Hey.

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.

Advertisements

2 Responses to “Mouse scroll wheel hack: update”

  1. Hi, I’m also trying to use the mouse scroll wheel with Processing.js. The links to your examples seem to be broken. Any chance of seeing how you solved this problem? Thanks!

  2. Hi SimsterJ,

    My solution is way out dated.

    If you look here: https://processing-js.lighthouseapp.com/projects/41284/tickets/230-mouse-scroll-wheel-support

    You can see the supported solution in there.

    It will look like this:

    void mouseScrolled() {
    if (mouseScroll > 0) {
    // scroll up
    } else if (mouseScroll < 0) {
    // scroll down
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: