resize height based on width

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelicdevil
    New Member
    • Apr 2009
    • 116

    resize height based on width

    i cud get it to resize based on width and height by setting them 100%...but now when i reduce the height even then it alters the size of the site...

    wat i want to do it based on width of the screen the height to be calculated and even if i reduce the height of the browser it should not deform...how can i get tht?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    so you want to have a fixed window-width-height ratio?

    Comment

    • angelicdevil
      New Member
      • Apr 2009
      • 116

      #3
      yes...it shud resize fully based only on width not height

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        try something like this:

        Code:
        var ratio = 4/3;
        
        window.onresize = function() {
            var w = window.innerWidth;
            var h = window.innerHeight;
        
            if (w/h != ratio) {
                window.resizeTo(w, w/ratio)
            }
        };

        Comment

        Working...