[英]Image is undefined when binding a drag event after onload
When in coffeescript I try to bind the dragstart event on an image in an onload trigger I get the following error: 在coffeescript中,当我尝试在onload触发器中将dragstart事件绑定到图像时,出现以下错误:
Uncaught TypeError: Cannot set property 'ondragstart' of undefined
Here's my code: 这是我的代码:
image_url = "some.url"
@image = $ new Image()
@image[0].onload = () =>
@image.on( 'dragstart', () -> false )
@image.attr 'src', image_url
Fixed it with this: 修复此问题:
@image[0].onload = () =>
@image.on 'mousedown', (e) -> e.preventDefault();
Mouse down, in combination with prevent default.. 按下鼠标,并结合使用默认设置。
In this example they do bind it like I do in the question though: http://eightmedia.github.com/hammer.js/slideshow/ 在此示例中,它们确实像在问题中一样进行绑定: http : //eightmedia.github.com/hammer.js/slideshow/
Still wondering what I'm missing here.. 仍然想知道我在这里缺少什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.