0

I am adding some new code to this Mootools slideshow.

I added thumbnails and a mouseover function that scrolls thru the thumbnails.
Now I need to make the timer on the slideshow stop/pause when mouseenter. I ma trying with the code under but got a Uncaught TypeError: Object #<HTMLDivElement> has no method '_stopClock'.

spinAreaDiv.addEvent('mouseenter', function(){
this._stopClock();  
})

How can I call the class _stopClock?

var Spin = new Class({
...
...
_stopClock:function(){
    if(!this.options.timer) { 
        return false; 
    } else {
        this.timerRunning = false;
        clearInterval(this.clock);
        this.timer.pause.addClass('active');
    }
},
...
4

1 回答 1

2

这是一个有约束力的问题。当来自 dom 事件的事件回调触发时,这将是元素。

element.addEvent('something', function(){
    this === element; // true;
});

// save a reference
var self = this;
element.addEvent('something', function(){
    this === element; // true;
    self._stockClock(); // works.
});

// or. use Function.prototype.bind
element.addEvent('something', function(){
    this !== element; // true;
    this._stopClock(); // works.
}.bind(this));

// or even...
this.element.addEvent('something', this._stopClock.bind(this)); // works.
于 2013-06-16T15:37:35.483 回答