0

Ok so basically I'm implementing a simple horizontal scroller. The function gets fired when I move the mouse into the correct div but only once and doesn't keep looping after the interval time. Any help appreciated:

$(document).ready(function() {
    $('#toparrow').mouseenter(function(e) {
        var func = scrollroller(1);
        setInterval(func,1);
    }).mouseleave(function() {

    });

    function scrollroller(velocity) {
        $('#roller').animate({left:'+='+velocity},1);
    }
});

2 Answers 2

2
var func = function(){ scrollroller(1); };
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is with this line:

var func = scrollroller(1);

This isn't assigning the scrollroller function to func, it is invoking scrollroller() with a parameter of '1' and storing the result in func. You probably want to do something like:

setInterval("scrollroller(1);",1);  //alternately:  setInterval(scrollroller,1,1);

Note that the alternate syntax may have issues in IE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.