欢迎来到 岁月小筑

如何在网页中调用岁月小筑随机图片API——背景图片

简介

本次以随机图片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,或使用开发者工具,屏蔽缓存。如果还没看到,那就请看下图:

岁月小筑随机网页背景图片 岁月小筑随机网页背景图片

点赞
  1. 倚竹聽雨说道:

    图片不错,可惜下一秒就是我的了。

  2. 已经调用,速度可以,不错 的感觉

  3. 喵喵喵博客说道:

    博主,请问可不可以换个友链,我已经加好了
    名称:喵喵喵博客
    网址:www.miaomiaomiao.org
    描述:大佬的梗子库

    1. littleplus说道:

      十分抱歉,小站友链已经太满了,再多的话不太好看

  4. 明月清风说道:

    这应该是必应的每日随机图片吧,图片都挺美丽的

    1. littleplus说道:

      不不不,这是自己手动从P站上保存下来的

      1. 明月清风说道:

        那还是挺厉害的哦!加油博主,不错

跨境电商培训进行回复 取消回复

电子邮件地址不会被公开。