A way around the one element-one tick would be to have an optional second argument on interval and timeout to label the tick. e.g. interval(1000, "abc")
...
bind("tick-abc", function() {})
Blair
On 10/20/06, Dave Methvin <[EMAIL PROTECTED]> wrote:
Since the event handling has recently been fixed to avoid IE memory leaks,
could we leverage that? After all, a timer is an event.
$("#time").interval(1000);
basically would map to this:
setInterval(function(){ $("#time").trigger("tick") }, 1000);
An interval of 0 would stop the timer. A one-time trigger could be done like
this:
$("#time").timeout(1000);
The handler looks like this:
$("#time").bind("tick", function(){
this.text(new Date());
});
BTW, _javascript_ timer receipts are just numbers so they can be assigned to
an object without causing a closure.
This approach would limit to one tick event per element--some might consider
that a feature--but you could always pass in another event name as the
second arg to timeout or interval.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
Behalf Of John Resig
Sent: Thursday, October 19, 2006 1:40 PM
To: jQuery Discussion.
Subject: Re: [jQuery] jQuery Kinda Plugin: every
What if you had a trifecta of functions:
.every()
.in()
.stop()
and allow for function calls like this:
.every( 100, "text", function(){
if ( !$(this).val() )
$(this).stop("text");
});
or if you don't care about a name:
.in( "slow", function(){
$(this).hide();
})
.mouseover(function(){
$(this).stop();
});
or if you wanna get really interesting, make it so that you can stop
function calls by how long their timer is set for:
.every( 500, function(){
$("#foo").load(" test.html");
})
.every( 100, function(){
if ( !$(this).val() )
$(this).stop(100);
});
Just throwing out some ideas, let me know which ones stick.
--John
On 10/19/06, Blair Mitchelmore < [EMAIL PROTECTED]> wrote:
> And I just realized I should make it possible to stop the repeating
> function later on.
>
> Code:
> jQuery.fn.every = function(interval,fn) {
> return this.each(function() {
> var self = this;
> this.$every = window.setInterval(function() { fn.call(self)
> },interval);
> });
> };
>
> Example:
> // Display the current time updated every 500 ms
> $("p.display").every(500,function() {
> $(this).html(new Date());
> });
>
> //... some point later in the code execution
> $("p.display").each(function() {
> window.clearInterval(this.$every);
> this.$every = null;
> });
>
> -blair
>
> Blair Mitchelmore wrote:
> > I don't know if this exists already but I needed this and assumed it
> > didn't and wrote it myself. Essentially it lets you do something to
> > an element every given time interval.
> >
> >
> > -blair
> >
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
_______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/