我在我的 Web 应用程序上使用 hammer.js
来实现手势功能。我用它来滑动视频元素,它的效果如预期的那样完美。但是,当我将以下代码应用于图像元素时,它不起作用。
App.Views.Photo = Backbone.View.extend({
template : template('photoTemplate'),
className : 'photo',
parent : null,
events: {
'swipe' : 'swiped',
// 'pan' : 'dragged'
},
...
swiped: function(e) {
this.remove();
this.parent.newContent(this.model);
},
这段完全相同的代码适用于视频元素,但不适用于图像。我还尝试在滑动函数中执行 e.gesture.preventDefault();
但这也不起作用。我目前正在 firefox 上测试该应用程序。
我们将不胜感激。
谢谢
[编辑]:我正在初始化锤子代码如下
render: function() {
$(this.el).attr('id', this.model.attributes._id);
this.$el.html( this.template( this.model.toJSON() ) );
this.$el.hammer();
return this;
},
最佳答案
您可以使用:
<img draggable="false"...
或者像这样在 CSS 中(可能不是所有浏览器都支持,尤其是 IE)
pointer-events: none;
关于javascript - Hammer.js:滑动事件不适用于图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26820656/