0

This works fine:

$('.mainRotatorPaginator a').click(function() {
    $(this).everyTime(1000, 'rotation', function(i) {
        $('.mainRotatorPaginator').css('outline', '1px solid green'); //test

    });
});

But I want a timer to start as soon as the page loads, not to wait for a user event.

I'm following the examples at http://plugins.jquery.com/project/timers, but this just isn't doing anything:

$(document).everyTime(1000, function (i) {
    $('.mainRotatorPaginator').css('outline', '1px solid green'); //test
}, 10);

Any help?

SOLUTION

OK, turns out the solution is related to Samich's (and Joe's) answer: even though all my jQuery calls were already nested inside $(document).ready in a file containing all my custom jQuery code, I tried pasting the suggestion anyway, just for giggles. To my surprise, this worked, and it turns out it's because I'd pasted the plugin inside the outer $(document).ready, but at the bottom, after the $(document).everyTime() call, so the file's code reached my call first, and the plugin's functions weren't yet defined.

So the best thing is to stick the plugin in it's own $(document).ready(function());, and place above the block where all my custom jQuery resides. (and I'll minify it first -- wondering why they don't offer a minified version?)

Faust
  • 15,130
  • 9
  • 54
  • 111

2 Answers2

2
$(document).ready(function()
{
    $(document).everyTime(1000, function (i) {
        $('.mainRotatorPaginator').css('outline', '1px solid green'); //test
    }, 10);
});
Joe
  • 15,669
  • 4
  • 48
  • 83
  • The code samples are already nested within $(document).ready(function(){ }); My apologies -- I thought that would be apparent given that I stated the first sample was working. – Faust Sep 09 '11 at 07:57
1
$(document).ready(function() {
    $(document).everyTime(1000, function (i) {
        $('.mainRotatorPaginator').css('outline', '1px solid green'); //test
    }, 10);
});

According to this post jquery "everyTime" function you can specify interval as string value

$(document).everyTime('1s', function (i) { })
Community
  • 1
  • 1
Samich
  • 29,157
  • 6
  • 68
  • 77
  • The code samples are already nested within $(document).ready(function(){ }); My apologies -- I thought that would be apparent given that I stated the first sample was working. – Faust Sep 09 '11 at 07:57