图片预加载
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<img id="img1" src="images/c.png" style="cursor:pointer" />
</body>
<script type="text/javascript">
var imgArr = ['images/1.jpg', 'images/9.jpg', 'images/243660.jpg', 'images/248967.jpg', 'images/284785.jpg', 'images/285684.jpg']
window.onload = preLoad();
var cutIndex = 0;
function preLoad() {
var imageObj = new Image();
if (cutIndex < imgArr.length) {
imageObj.src = imgArr[cutIndex];
cutIndex++;
preLoad()
}
}
var img1 = document.getElementById('img1');
var index = 0;
img1.onclick = function() {
img1.src = imgArr[index++];
}
</script>
</html>
图片懒加载
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
img {
display: block;
}
#ul1 {
width: 808px;
margin: 0 auto