Closed spencermountain closed 11 years ago
One way that would work is to use the oj.onload function. Pass it a function as the first arg, and it will be called at the right time!
For example in CoffeeScript:
oj.span c:'my-span', "hi"
oj.onload ->
$('.my-span').animate ...
You can also use the Text object to avoid the need for a class name:
myText = oj.Text 'Hi', tagName:'span'
oj.onload ->
myText.$el.animate ...
Clearly this is still somewhat indirect so I'll have to think about adding an event. A load event makes sense, though maybe an animate event would too? Is animation your main goal? Let me know if this works for you!
aww, thanks. yes exactly. i've been adding random ids to elements just so i can do some ad-hoc javascript on them, once they're in the dom. any way of getting a element as a '$(this)', in the same oj template, would be really awesome. happy to help with this -spence
@spencermountain Just for you buddy: OJ now supports "insert" events that are called when elements are inserted into the page: http://jsfiddle.net/evanmoran/Ps4ms/
This seemed a clearer name then load
, since technically the page's can only happen once, and OJ can insert many times.
Both the first arg and this
are the element:
insert: (el) -> $(el).animate ...
Or
insert: -> $(this).animate ...
Let me know if that works for you!
YOU ARE THE COOLEST EVER
Hi Evan, one thing I've been getting stuck with is a nice way to attach events to dom elements once they're loaded. Something like this:
span { load: -> $(this).animate({...}) }, "hi"
What would be the way you recommend to do this? reactive coffee made a 'init' method, in addition to the available jquery listeners, but maybe there's already a clever way to do it. Cheers,