return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Holder.js -- Get back DOM element? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Holder.js -- Get back DOM element? - Stack Overflow

programmeradmin3浏览0评论

holder.js

I want to dynamically add a placeholder image to my page.

Inserting it like so doesn't work:

$('<li>',{class:'file-item'})
    .append($('<img>',{'data-src':'holder.js/150x150'}))
    .append($('<span>',{class:'file-name'}).text(file.name))
    .appendTo('#file-list');

Because the holder script has already ran and isn't searching for new elements.

We can, however, run it again manually:

Holder.run()

But then it will scan all the elements that are already added.

So...is there way I can get holder.js to create and give me back a DOM element so I can add it manually without re-running the whole thing?

holder.js

I want to dynamically add a placeholder image to my page.

Inserting it like so doesn't work:

$('<li>',{class:'file-item'})
    .append($('<img>',{'data-src':'holder.js/150x150'}))
    .append($('<span>',{class:'file-name'}).text(file.name))
    .appendTo('#file-list');

Because the holder script has already ran and isn't searching for new elements.

We can, however, run it again manually:

Holder.run()

But then it will scan all the elements that are already added.

So...is there way I can get holder.js to create and give me back a DOM element so I can add it manually without re-running the whole thing?

Share Improve this question edited Feb 16, 2013 at 21:25 mpen asked Feb 16, 2013 at 21:20 mpenmpen 284k281 gold badges892 silver badges1.3k bronze badges 6
  • Holder is a jQuery plugin? Something else? – the system Commented Feb 16, 2013 at 21:23
  • Seems like there is an add_image method that could possibly handle this – Explosion Pills Commented Feb 16, 2013 at 21:23
  • 1 ...beware of {class:'file-name'}. It'll break in some older browsers. Use className or "class". – the system Commented Feb 16, 2013 at 21:24
  • @thesystem: holder.js is a standalone library for generating placeholder images. It's used in Twitter Bootstrap. Added link to question. – mpen Commented Feb 16, 2013 at 21:25
  • @thesystem: Excellent point about the class property. I did run into that before (in IE I think) and it confused the heck out of me. Gave a very misleading error. – mpen Commented Feb 16, 2013 at 21:26
 |  Show 1 more ment

1 Answer 1

Reset to default 8

Pass a Node as the images property to Holder.run and you'll be able to run Holder on any individual image. Holder itself doesn't create a DOM element, it just changes the src value.

Code:

var image = $("<img>").attr({
    "data-src": "holder.js/300x200"
})

Holder.run({
    images: image[0]
});

image.appendTo("body");

Live example here: http://jsfiddle/imsky/p3DMa/

发布评论

评论列表(0)

  1. 暂无评论