JS Background Resize issue.

Out of context: Reply #11

  • Started
  • Last post
  • 12 Responses
  • ornj0

    Uniform scaling:

    function bgResize() {
    $('.background').each(function(i...
    var bg = $(this);
    var w = $(window);

    var width_diff = w.height() / bg.height() * bg.width();
    var height_diff = w.width() / bg.width() * bg.height();

    if(height_diff > w.height()) {
    bg.width(w.width()+'px');
    bg.height(height_diff+'px');
    } else {
    bg.width(width_diff+'px');
    bg.height(w.height()+'px');
    }
    });
    }

    // Resize the background image when the window scales
    $(window).resize(function(){
    bgResize();
    });

    // Make rocket go now!
    $(document).ready(function(){
    bgResize();
    });

View thread