javascript - jquery mouseup 无法正常工作

标签 javascript jquery html

http://igt.bitballoon.com/

上面是引用网站,我正在使用一些 jquery 函数,但我不知道为什么 mouseup 不起作用。

这是位于头部内部的 jquery,是的,我也在那里引用了 jquery

$(document).ready(function()
{
    $("#Clickables").mouseup(function() 
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickani.png") no-repeat center', "background-size":"75% 75%"});
    });

    $("#Clickables").mouseout(function() 
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickani.png") no-repeat center', "background-size":"75% 75%"});
    });

    $("#Clickables").mousedown(function()
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickdown.png") no-repeat center', "background-size":"75% 75%"});
    });
});

这是相关的 html

<div id="Clickables" class="blockclicker" onclick="GatherMoney();">
</div>

我想要发生的事情:当单击图像时,我希望只要鼠标按下,它就会发生变化,并在用户放开或离开该区域时变回原始状态。 mousedown 和 mouseout 事件工作正常。这是没有意义的,因为当我创建 mouseout 事件时,我只是复制并粘贴 mouseup 事件并更改了该事件。 问题是什么: mouseup 事件不会放回具有其属性的原始图像,我相信它是正确的图像,但不重复中心和大小不适用,但它们适用于 mouseout 功能。

我很困惑

最佳答案

你能试试这个吗?我已经尝试过here

$(document).ready(function()
{
    $("#Clickables").mouseup(function() 
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickani.png") no-repeat center', "background-size":"75% 75%"});
    });

    $("#Clickables").mouseout(function() 
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickani.png") no-repeat center', "background-size":"75% 75%"});
    });

    $("#Clickables").mousedown(function()
    {
        $(this).css({"background":'url("http://igt.bitballoon.com/images/clickdown.png") no-repeat center', "background-size":"75% 75%"});
    });
});

<div id="Clickables" class="blockclicker" style="height:200px; width:200px;" onclick="GatherMoney();">
  <button>click here</button>
</div>

关于javascript - jquery mouseup 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44344561/

相关文章:

javascript - 如何在调用对象之前调用函数

javascript - 为什么 localStorage 的 jquery 深复制不起作用?

jquery - 防止Bootstrap崩溃崩溃

javascript - 将外部 jsx 文件添加到 html 页面( react )

c# - JavaScript - 如何在 Javascript 中为 Session 设置值

javascript - 如果 overflow hidden 的父元素为 "cut",则删除子元素

php - anchor 标记在切换 div 中不起作用

javascript - 用于导航用户的 Angular 三元运算符

javascript - 在 Javascript 中按值传递变量

javascript - Laravel @include 通过 ajax 的 Blade View