I want to do the same thing as you can see at youassist.org.
Look at the image in the slide show, and try to resize the browser window*. You can see two "behaviors" on the displaying of the image:
- with larger window the image will gradually zoom in;
- with smaller window** the image doesn't zoom out but it scroll horizontally.
I'm trying to do that. This is what I've got so far, but it only works if I resize from a big window to a smaller window, but not vice versa.
Here is a fiddle:
HTML:
<div class="page-header-2">
<img class="img-header" src="http://youassist.org/assets/home1.jpg" />
</div>
CSS:
.page-header-2{
height:350px;
overflow:hidden;
width:100%;
background:red;
}
.img-big{
width: 100%;
}
.img-small{
height: 100%;
max-width: none;
}
Script:
var imgH = $(".page-header-2 img").height();
var divH = $(".page-header-2").height();
if(imgH <= divH){
$(".page-header-2 img").addClass("img-small");
} else {
$(".page-header-2 img").addClass("img-big");
}
$(window).resize(function() {
var imgH = $(".page-header-2 img").height();
var divH = $(".page-header-2").height();
if(imgH <= divH){
$(".page-header-2 img").removeClass("img-big");
$(".page-header-2 img").addClass("img-small");
} else {
$(".page-header-2 img").removeClass("img-small");
$(".page-header-2 img").addClass("img-big");
}
});
*: resize the window gradually and don't go beyond the point where the site reorganizes itself as responsive site for mobile. I'm not interesting in that!
**: "smaller window" isn't correct, I think this behaviour occurs when the image size is smaller than the window size