onload for image

41 views
Skip to first unread message

maximL

unread,
Apr 2, 2012, 8:35:38 AM4/2/12
to RightJS
Здравствуйте!
Подскажите, пожалуйста

1. Как перехватить событие "onload" для изображения.
var tempImage = $E('img', {src: 'http://nnn.jpg'})
tempImage.onload(function(){...})
2. Каким образом получить ссылку на 'element' в событии Fx ->
onFinish:
element.morph({ ... },{onFinish: function(){ . . . }})

Спасибо!

nicksan

unread,
Apr 2, 2012, 8:54:11 AM4/2/12
to RightJS
Hi!
A first try like this:

<div id="t1"></div>
<script>
var e=$E('img', {
src: '/tree-open.gif',
on:{
load:function(){ alert('I am loading!');}
}
});

$('t1').insert(e);
</script>

Nikolay Nemshilov

unread,
Apr 2, 2012, 9:45:37 AM4/2/12
to rig...@googlegroups.com
Плз, пишите на русском в rightjs4ru


RightJS works with something called dom-wrappers, when you make a call like `new Element` or `$E(` or just `$('something')` it returns you a javascript object that represents your dom-element, but that's not the actual element. The element is referred by using the the `._` attribute. For example

var el = $E('div');

console.log(el); // will show the RightJS dom-wrapper object
console.log(el._); // will show the actual raw dom-element

So, to answer your question, you should either use RightJS `.on(` method, like nicksan suggested

var el = $E('img');
el.on('load', function() {...});
el.set('src', 'some-image.jpg');

That is preferred and less troublesome solution. But, if you feel particularly evil, you can assign that function directly as you initially tried.

var el = $E('img');

el._.onload = function() {
console.log("kids, don't do that");
};


I hope, that helps

> --
> You received this message because you are subscribed to the Google Groups "RightJS" group.
> To post to this group, send email to rig...@googlegroups.com.
> To unsubscribe from this group, send email to rightjs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rightjs?hl=en.
>

maximL

unread,
Apr 3, 2012, 8:56:55 PM4/3/12
to RightJS
Thank you very much for your help!
Reply all
Reply to author
Forward
0 new messages