Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击背景时使用onmousedown设置动画_Javascript_Html_Background Image - Fatal编程技术网

Javascript 单击背景时使用onmousedown设置动画

Javascript 单击背景时使用onmousedown设置动画,javascript,html,background-image,Javascript,Html,Background Image,我的HTML页面中有一个小图像。我需要它是动画,当我点击网页的背景?我知道我必须通过onmousefunction来实现这一点,但是当我将该函数添加到body标记中时,它不起作用 <script> <body background = "src\img.jpg" onmousedown:moveRight();> </body> </script> 您想要的是“onclick=moveRight()”而不是“onmouseclick:moveR

我的HTML页面中有一个小图像。我需要它是动画,当我点击网页的背景?我知道我必须通过
onmousefunction
来实现这一点,但是当我将该函数添加到
body
标记中时,它不起作用

<script>
<body background = "src\img.jpg" onmousedown:moveRight();>

</body>
</script>

您想要的是“onclick=moveRight()”而不是“onmouseclick:moveRight()”

只需在页面上设置一个EventListener,并将您的函数添加到其中,无需内联javascript:

window.onload = function() {
document.addEventListener('click', moveRight);

}
html:
/*************************************************************/
不要在脚本标记内编写html

 html:
    <body background = "src\img.jpg" onclick=moveRight();>   
    </body>
/*************************************************************/
<body background = "src\img.jpg" onmousedown=moveRight();>   
    </body>