+0
日增长
5,789
stars
581
forks
194
watchers
70
prs
168
issues
4
releases
README
Holder
!
Holder renders image placeholders in browser using SVG.
Used by thousands of open source projects (including Bootstrap v3) and many other sites.
No extra requests, small bundle size, highly customizable.
Installing
npm: npm install holderjs
yarn: yarn add holderjs
unpkg:
cdnjs:
jsDelivr:
Bower: bower install holderjs
Rails Assets: gem 'rails-assets-holderjs'
Meteor: meteor add imsky:holder
Composer: php composer.phar update imsky/holder
NuGet: Install-Package Holder.js
Usage
Include holder.js in your HTML:
html
Holder will then process all images with a specific src attribute, like this one:
html
The above tag will render as a placeholder 300 pixels wide and 200 pixels tall.
To avoid console 404 errors, you can use data-src instead of src.
Programmatic usage
To programmatically insert a placeholder use the run() API:
js
var myImage = document.getElementById('myImage');
Holder.run({
images: myImage
});
Placeholder options
Placeholder options are set through URL properties, e.g. holder.js/300x200?x=y&a=b. Multiple options are separated by the & character.
theme: The theme to use for the placeholder. Example: holder.js/300x200?theme=sky
random: Use random theme. Example: holder.js/300x200?random=yes
bg: Background color. Example: holder.js/300x200?bg=2a2025
fg: Foreground (text) color. Example: holder.js/300x200?fg=ffffff
text: Custom text. Example: holder.js/300x200?text=Hello
size: Custom text size. Defaults to pt units. Example: holder.js/300x200?size=50
font: Custom text font. Example: holder.js/300x200?font=Helvetica
align: Custom text alignment (left, right). Example: holder.js/300x200?align=left
outline: Draw outline and diagonals for placeholder. Example: holder.js/300x200?outline=yes
lineWrap: Maximum line length to image width ratio. Example: holder.js/300x200?lineWrap=0.5
Themes
!!!
Holder includes support for themes, to help placeholders blend in with your layout.
There are 6 default themes: sky, vine, lava, gray, industrial, and social.
Customizing themes
Themes have 5 properties: fg, bg, size, font and fontweight. The size property specifies the minimum font size for the theme. The fontweight default value is bold. You can create a sample theme like this:
js
Holder.addTheme("dark", {
bg: "000",
fg: "aaa",
size: 11,
font: "Monaco",
fontweight: "normal"
});
If you have a group of placeholders where you'd like to use particular text, you can do so by adding a text property to the theme:
js
Holder.addTheme("thumbnail", { bg: "fff", text: "Thumbnail" });
Using custom themes
There are two ways to use custom themes with Holder:
Include theme at runtime to render placeholders already using the theme name
Include theme at any point and re-render placeholders that are using the theme name
The first approach is the easiest. After you include holder.js, add a script tag that adds the theme you want:
html
Holder.addTheme("bright", {
bg: "white", Top issues
#176RTL support8 comments · 2016-01-25#202Holderjs with Material Icons continued 7 comments · 2016-10-31#181Support for old format6 comments · 2016-04-01#196Text vertical alignment4 comments · 2016-08-16#195Using holder with <picture> element doesn't work ?4 comments · 2016-08-13#185Content security policy4 comments · 2016-05-18#114Official WordPress plugin4 comments · 2014-10-09#234Need to replace `robloach/component-installer`3 comments · 2021-01-13
Latest release
Holder 2.8 v2.8.0 2015-06-02- Outlines with diagonals can now be drawn using the outline option. - Text color is now automatically set if no foreground color is specified. - Text margin can now be controlled using the run-time lineWrapRatio option. - addImage now supports a DOM node (or nodes) as argument - SVG and DOM functions have been factored out into modules. - Scene graph code has been rewritten to use plain JS, augment.js has been removed. - Flag processing code has been removed. - README has been updated with more documentation of internal options.