html5图片自适应页面宽高比的特效

来源:https://www.sucaihuo.com/js/3046.html 2017-09-19 15:32浏览(1456) 收藏

一款html5图片自适应页面宽高比的特效,这里用了html5的picture元素来处理响应式图片,调整页面窗口的大小就能看到效果了。
html5图片自适应页面宽高比的特效
分类:html5 难易:初级
查看演示 下载资源 下载积分: 20 积分

页面的head部分,需引入页面元素的样式文件,代码如下:

<link type="text/css" rel="stylesheet" href="css/style.css">

页面的body部分,主要时picture元素,根据不同的窗口大小来处理图片的宽高比,代码如下:

<p>请调整页面窗口大小查看效果</p>
<picture>
  <source media="(max-width: 400px)" srcset="https://cdn.somedomain.tech/samples/girl-on-bridge.jpg?quality=80&width=400&height=600&resizeStyle=entropy">
  <source media="(max-width: 800px)" srcset="https://cdn.somedomain.tech/samples/girl-on-bridge.jpg?quality=80&width=800&height=800&resizeStyle=entropy">
  <img src="https://cdn.somedomain.tech/samples/girl-on-bridge.jpg?quality=80">
</picture>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2