There is no fixed correct height. If I set a fixed height in css, the image will not change with the correct aspect ratio in my responsive layout.
, css , src, width- height. , , . ( 1x1), , , html, css ( css -).
, , "height: auto" " " " " jquery :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<style type="text/css">
img {
max-width: 100%;
}
.lazy-loaded {
height: auto;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script language="JavaScript">
$(document).ready(function(){
resizeBlankImages();
});
$(window).resize(function(){
resizeBlankImages();
});
function resizeBlankImages() {
$(".lazy-blank").each(function () {
var originalWidth = $(this).attr('width');
var originalHeight = $(this).attr('height');
var ratio = originalWidth/originalHeight;
var width = $(this).width();
var height = width/ratio;
$(this).height(height);
});
}
</script>
</head>
<body>
<img data-original="image.jpg" src="image.jpg" class="lazy lazy-loaded" width="500" height="300">
<br/>
<img data-original="image.jpg" src="blank.gif" class="lazy lazy-blank" width="500" height="300">
</body>
</html>
, . ?