如果不在同一元素上释放,则丢失MouseUp事件 [英] Losing MouseUp event if releasing not over the same element

查看:119
本文介绍了如果不在同一元素上释放,则丢失MouseUp事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到滑块问题。当我抓住处理程序时,我改变图像的.src,只是为了改变它的颜色。但是,我希望它在我释放鼠标按钮时更改回原始颜色。我尝试了两件事。

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)在处理程序mouseup事件上更改它:这只有在我释放处理程序上的按钮时才有效,所以这不是一个解决方案。

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它返回窗口mouseup事件:事件未正常触发。如果我在窗口的任何位置单击并释放,则事件会正常触发,但如果我单击处理程序,将光标移动到窗口的任何其他位置,然后释放按钮,事件将不会触发。

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.

顺便说一句,即时通讯使用原型js框架。

Btw, im using the prototype js framework.

解决方案?谢谢

这是代码。我在文档准备就绪时加载了处理函数。

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

}


推荐答案

您应该将 mouseup 处理程序附加到文档对象。

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

这篇关于如果不在同一元素上释放,则丢失MouseUp事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆