0

我正在尝试实现这个滚动功能,它应该可以工作,但是当我尝试时,它给了我一个语法错误。有人可以告诉我为什么/如何解决它吗?

Scroller = function(element) {
  this.element = this;
  this.startTouchY = 0;
  this.animateTo(0);

  element.addEventListener('touchstart', this, false);
  element.addEventListener('touchmove', this, false);
  element.addEventListener('touchend', this, false);
}

我确定我必须改变Scroller = function(element),但我不知道要改变什么。

4

1 回答 1

1

这:

element.addEventListener(‘touchstart’, this, false);
element.addEventListener(‘touchmove’, this, false);
element.addEventListener(‘touchend’, this, false);

应该是这样的:

element.addEventListener('touchstart', this, false);
element.addEventListener('touchmove', this, false);
element.addEventListener('touchend', this, false);

不同之处在于我用普通的单引号替换了样式引号。你是用 Word 还是什么的?!

你还应该改变这个:

var Scroller = function() {

对此:

function Scroller() {
于 2012-04-17T03:46:43.267 回答