0

I have a dedicated image area on my html page. This area vary from the screen resolution. I have a javascript to resize these area accordingly. The problem is that on every reload my image is jumping to full size and back to fit which creates very nasty visual effect.

Can anyone advise me how to proceed and how to properly resize this image?

EDIT: The purpose of the resize code is to have the full height of the parent container.

    var windowHeight = $(window).height() - $("#myCarousel").offset().top ;

    $('#myCarousel .carousel-inner div img').css({
        height: (windowHeight) + 'px'
    })
2
  • Perhaps if you share your HTML & JavaScript we may be able to advise how to correct it, rather than starting from scratch. Commented Oct 26, 2015 at 13:18
  • 2
    Please share the code with the issue. Also, why you use JS to make that element responsive? Commented Oct 26, 2015 at 13:18

1 Answer 1

2

Your page jumps cause JS waits for document ready or worse for window load,
calculating the best fit for your image (apparently) and than triggering resize and browser redraw.

Don't use JS to make your elements responsive, use CSS and % size.

Sometimes the best way to show a large picture and make it nicely responsive is to set it as background-image:

<div id="heroImage" style="background-image:url(images/largeImage.jpg)"></div>

having this CSS:

#heroImage{
    height: 900px;                 /* for browsers who don't support "viewport" vh/vw */
    height: 100vh;
    background: 50% / cover;       /* use cover, contain or a %size */
}

jsBin demo ← resize and have fun

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.