以下是完整代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>gao</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="renderer" content="webkit">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
</head>
<body>
<div class="placeholder" >
<img src="https://cdn-images-1.medium.com/freeze/max/27/1*sg-uLNm73whmdOgKlrQdZA.jpeg?q=20"
data-large="https://cdn-images-1.medium.com/max/1800/1*sg-uLNm73whmdOgKlrQdZA.jpeg"
class="img-small">
<div style="padding-bottom: 66.6%;"></div>
</div>
</body>
<style>
.placeholder img {
width: 100%;
}
</style>
<script>
window.onload = function() {
var placeholder = document.querySelector('.placeholder'),
image = placeholder.querySelector('.img-small')
// load large image
var imgLarge = new Image();
imgLarge.src = image.dataset.large; //大图地址
imgLarge.onload = function () {
image.src = image.dataset.large //大图地址
};
}
</script>
</html>
复制代码