我正在尝试使用java脚本在图像上添加标签。图像缓存在第一次加载图像时创建缓存的图像,因此当java脚本代码试图将标签添加到图像上时,它会将它们放在错误的位置,因为图像还没有准备好。它将它们放在一条线上。当第二次调用java脚本代码时,它会将标签放在正确的位置,因为已经创建了缓存的图像。
如何在java脚本域中理解图像缓存完成了它的任务并创建了缓存的图像?
图像被放置在id为'#tag_container‘的div中,图像的id为'#imagecache_taggable_image’
Drupal.behaviors.tagRestore = function (context) {
...
...
$('#tag_container').addAnnotations(tag_locations );
// first time I called addAnnotations #imagecache_taggable_image is not ready
// so that it places tags wrong places as a line
...
...
}致以良好的问候..。
发布于 2013-03-11 05:33:51
我相信图像的onload事件应该会对此有所帮助。
http://www.w3schools.com/jsref/dom_obj_image.asp
以下是示例jQuery代码:
$('#imagecache_taggable_image').bind('load', function() {
console.log('loaded', this);
//do custom code here
});https://stackoverflow.com/questions/13788248
复制相似问题