0

I'm searching for a way to make a header animation like this one.

I have found a solution on this post, but it's not working with images. I changed the code like this:

<div id="header_nav"><img src="http://placehold.it/90x90" /></div>

http://jsfiddle.net/JJ8Jc/72/

What can I do? Thanks for the help.

Question: How can I scale the image in the header with its div aswell?

Any help would be appreciated!

Community
  • 1
  • 1
trikutin
  • 197
  • 1
  • 2
  • 16

3 Answers3

0

Add overflow: hidden to #header_nav and the image will be cropped by the element's height: Working demo.

Or, add max-height: 100%; max-width: 100% to the image to make it shrink with the height of the element: Working demo.

freejosh
  • 11,263
  • 4
  • 33
  • 47
  • Thanks this is working good too but also this one have a same image pixelate problem. – trikutin Jul 09 '13 at 13:37
  • The example site you posted scales their image in the same way. If the image doesn't contain very intricate details you won't see as many artifacts. The Salient logo consists of thick letters and a shape with solid colors, for example. – freejosh Jul 09 '13 at 13:41
0

Shrink the image as the header gets shrinked?

Fiddle.

$(function(){
    $('#header_nav').data('size','big');
});

$(window).scroll(function(){
    if($(document).scrollTop() > 0)
    {
        if($('#header_nav').data('size') == 'big')
        {
            $('#header_nav').data('size','small');
            $('#header_nav').stop().animate({
                height:'40px'
            },600);
            $('#header_nav img').stop().animate({
                height:'40px' /*image has the same effect like the header*/
            },600);
        }
    }
    else
    {
        if($('#header_nav').data('size') == 'small')
        {
            $('#header_nav').data('size','big');
            $('#header_nav').stop().animate({
                height:'100px'
            },600);
            $('#header_nav img').stop().animate({
                height:'100px' /*image has the same effect like the header*/
            },600);
        }  
    }
});
Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113
0

I you want to crop the image add overflow: hidden to the parent of the image (#header_nav) and if you want that the image shrink with the header add max-height: 100%; to the image.

Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75