欢迎来到 岁月小筑

如何在网页中调用岁月小筑随机图片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. Zero说道:

    话不多说 支持!

  2. 非常不错!!!!

  3. 挺不错的。就是我这博客不太适合这种改背景。

  4. siyochen说道:

    左下角的妹子有点意思,

    1. littleplus说道:

      是吧,我也觉得有意思,就是突然说一些话猝不及防

  5. 嘿嘿说道:

    想知道网站左下角的妹子怎么实现的大佬

    1. littleplus说道:

      文章已水,大佬请查阅

      1. 嘿嘿说道:

        我喜欢你博客的那种,.......

littleplus进行回复 取消回复

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