Created
October 31, 2016 16:35
-
-
Save aligator28/b5d7743da0de8902383a706cf6aa7de2 to your computer and use it in GitHub Desktop.
Images preloading javascript (предзагрузка изображений js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Rotate Image</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row" id="img1"></div> | |
<div class="row" id="img2"></div> | |
<div class="row" id="img3"></div> | |
<div class="row" id="img4"></div> | |
<div class="row" id="img5"></div> | |
</div> | |
<script type="text/javascript" src="jquery-1.11.2.min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
function preloadImg(containerId, imgUrl) { | |
var cont = $('#' + containerId); | |
var i = new Image(); | |
i.onload = function () { | |
cont.append(this); | |
cont.fadeIn('slow'); | |
}; | |
i.src = imgUrl; | |
} | |
var images = { | |
'img1': 'http://loremflickr.com/200/300/girl', | |
'img2': 'img/2girl.jpg', | |
'img3': 'img/3girl.jpg', | |
'img4': 'img/4girl.jpg', | |
'img5': 'img/5girl.jpg', | |
}; | |
$.each(images, function (key, val) { | |
preloadImg(key, val); | |
}) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment