views:

59

answers:

3

I have got a problem with a slider. When i grab the handler, i change the .src of the image, just to change its color. However, i want it to change back to the original color when i release the mouse button. I have tried two things.

1) Changing it back on the handler mouseup event: this works only if i release the button over the handler, so this is not a solution.

2)Changin it back on the window mouseup event: the event is not firing properly. If i click and release on any place of the window, the event fires normaly, but if i click in the handler, move the cursor to any other point of the window, and then release the button, the event will not fire.

Btw, im using the prototype js framework.

Solutions? Thanks

Here is the code. I load the handler function when the document is ready.

function handler()
{

    var handler = $('handler');

    Event.observe(window, "mouseup", function(){
        alert('salta');   //to see when mouseup fires
        if(handler.src=='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper_o.png'){    //orange
            handler.src='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper.png';}    //grey
    });


    Event.observe(handler,'mousedown',function(){handler.src='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper_o.png';});    //orange

}
+1  A: 

How about onmouseout event?

amorfis
That's not what im looking at. onmouseout will fire if you move the cursor out of a slider. However you are still controlling the slider slider even if you move the cursor to any place on the windowuntil you release the button. And, if you are controlling the slider, the slider is colored, thats what i want.
Alberto Mnemon
A: 

You should be attaching the mouseup handler to the document object.

lincolnk
im sorry, can you explain yourself a little more?
Alberto Mnemon
your function which sets the slider back to the original color should be called when `document` detects `mouseup`, not when your slider element does. attaching to `document` will call the event handler if you release the mouse anywhere in the web page, not just over your slider. post your non-working code if you want more specific help fixing it.
lincolnk
That seems exactly what i am doing, maybe you didnt understand me because of my english. I'll post the code to make things clear for all of us.
Alberto Mnemon
yes, that worked! As u said, i was attaching it to the window, not to the document. Thanks lincolnk, and sorry about the code!
Alberto Mnemon
A: 

Here is the code. I load the handler function when the document is ready.

function handler()
{

    var handler = $('handler');

    Event.observe(window, "mouseup", function(){
        alert('salta');   //to see when mouseup fires
        if(handler.src=='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper_o.png'){    //orange
            handler.src='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper.png';}    //grey
    });


    Event.observe(handler,'mousedown',function(){handler.src='http://localhost/moodle/blocks/videoavatar/eggface/trunk/gripper_o.png';});    //orange

}
Alberto Mnemon
this should be edited in to your original post, not added as an answer. I edited your question, this can be deleted.
lincolnk