Image's placeholder.If image loading failure,placeholder image will shown in image's position.
图像占位符。当图片加载失败的时候,占位符图片会显示在失败的图片位置上。
Import Script Download
<script src="path/to/image-placeholder/image-placeholder(.min).js"></script>
// use with node
var img = document.querySelector('#image');
placeholder(img);
// use with selector
placeholder('#image');
// use with options
placeholder('#image',{
icon:true,
text:'Image loading failure'
})
// get canvas object
var canvas = placeholder.getCanvas({
height:120,
width:200
});
// get base64 data
var base64Data = placeholder.getBase64Data({
height:120,
width:200,
icon:true
});
-
width : placeholder's width
- type:
number
- default: if use
placeholder
function,default value is image's width.if useplaceholder.getCanvas
orplaceholder.getBase64Data
no default value andwidth
is required.
- type:
-
height:placeholder's height
- type:
number
- default: if use
placeholder
function,default value is image's height.if useplaceholder.getCanvas
orplaceholder.getBase64Data
no default value andheight
is required.
- type:
-
icon:show icon or not.
- type:
boolean
- default:
false
- type:
-
iconWidth:icon's width when
icon
is set to betrue
- type:
number
- default:15% of the placeholder's width
- type:
-
iconHeight:icon's height when
icon
is set to betrue
- type:
number
- default:15% of the placeholder's height
- type:
-
text:text shown on the placeholder
- type:
string
- default:
"image is unavailable"
- type:
-
fontSize:font size of the text
- type :
number
- default : 15% of the minimum between placeholder's width and height
- type :
-
bgColor:background color of the placeholder
- type :
string
- default : "#ddd"
- type :
-
textColor:text color of the placeholder
- type :
string
- default : "#fff"
- type :
MIT license