简介
本次以随机图片API中的环境背景图片为例子,调用地址为:
https(推荐): https://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302 http(更快,快一点点,不安全,可能会被劫持): http://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302
如果需要人物背景图片,请把ctype的值由nature修改为acg,或留空,如:
https(推荐): https://img.xjh.me/random_img.php?type=bg&ctype=acg&return=302 http(更快,快一点点,不安全,可能会被劫持): http://img.xjh.me/random_img.php?type=bg&ctype=acg&return=302
使用方法
用法一:直接写入网页
直接在标签中添加
style="background-repeat:no-repeat; background-attachment:fixed;background-size:cover;background-image: url(https://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302);"
此方法略微提升加载速度?(怀疑)
用法二:写入CSS样式文件
当要插入的标签含特定id时,使用: #id{background-repeat:no-repeat; background-attachment:fixed;background-size:cover;background-image: url(https://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302);} 当要插入的标签含特定class时,使用 .class{background-repeat:no-repeat; background-attachment:fixed;background-size:cover;background-image: url(https://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302);}
效果图:
请参考本站背景,如果没看到,请刷新浏览器缓存,Ctrl+F5,或使用开发者工具,屏蔽缓存。如果还没看到,那就请看下图:
我在首页幻灯片引用一下
你还真的就引用一下啊
好了,现在首页两张图全部引用自img.xjh.me
换回七牛了,图片尺寸和体积太大,不适合我的首页banner使用。
尺寸这个没什么啊,反正是自适应的,至于体积,不是跟你现在的差不多100KB左右吗?
53473150_p0.jpg 280KiB,59190594_p0.jpg 371KiB,63606459_p0.jpg 221KiB,对于一个700px*250px的banner太奢侈了,自己切了切丢七牛了。
自选图片会不会不清晰
自选是什么意思?
给新主题安上啦,发现好多图片,都看过
感觉蛮棒,拿去做背景图啦~