Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  97] [ 7]  / answers: 1 / hits: 26430  / 12 Years ago, fri, april 6, 2012, 12:00:00

I'm trying to have a div's left property change by its self - one every second when your hovering over so I made this:



$(div.scroll_left).hover(function(){
var left_num = $('div.license_video').css(left)
var left_num1 = parseInt(left_num, 10) - 1;
var timerID = setInterval(alert(left_num1), 1000);
//var timerID = setInterval(slideleft(left_num1), 1000);
},function(){
clearInterval(timerID);
});
//function slideleft(left_num){
//$('.license_video').css('left', left_num + %);
//}


In theory you would think it repeat till you move your cursor off which clears the interval. When I hover over it does it one time and never repeats (there are no errors). Then when I hover off it gives a error Uncaught ReferenceError: timerID is not defined


More From » jquery

 Answers
13

setInterval isn't working at all. You aren't passing it a function as the first argument.



You are calling alert immediately and trying to use it's return value as the function to repeat.



var timerID = setInterval(function () { alert(left_num1) }, 1000);

[#86383] Thursday, April 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maurodannyr

Total Points: 126
Total Questions: 103
Total Answers: 105

Location: Maldives
Member since Sun, Feb 27, 2022
2 Years ago
;