Solved

Min/Max height vs JS / jQuery / MooTools resize for website

Posted on 2011-02-16
4
863 Views
Last Modified: 2012-05-11
Hey guys!

I am creating a website, and would like to make the website resize depending on the user's browser window size (realtime if possible). It will be a E-Commerce shopping cart, so there will be a lot of different size images, content, and buttons to consider also.

The question is, what it be feasible to make the ENTIRE website resizable depending on the user's browser window?

If so, would it be better / easier to use JS for this or CSS (min-height,max-height)? Everything will be dependent on the height of the browser, not the width of it.

The images will be dependent on ratios (2/3). The website currently has a mixture of MooTools and jQuery, where some pages either contain one or the other.

Please let me know what you think.

Thanks!
0
Comment
Question by:areyouamac
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
imantas earned 500 total points
ID: 34912847
CSS won't help you here enough. Use javascript, something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <title>Blank page</title>
 <meta name="viewport" content="width=device-width,user-scalable=no"/>
</head>
<body>
Window width: <input id="width" type="text" size="10" /><br/>
Window height: <input id="height" type="text" size="10" />

<script type="text/javascript">
<!--
    window.size = function () {
      var windowWidth, windowHeight;
      if (typeof window.innerWidth != 'undefined') {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
      }
      else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight
      }
      else if (document.getElementsByTagName && document.getElementsByTagName('body').length > 0) {
        windowWidth = document.getElementsByTagName('body')[0].clientWidth;
        windowHeight = document.getElementsByTagName('body')[0].clientHeight;
      }
      window.width = window.w = windowWidth;
      window.height = window.h = windowHeight;
      
      return { w: windowWidth, h: windowHeight, width: windowWidth, height: windowHeight };
    };
    window.onresize = function() {
      document.getElementById('width').value = window.size().width + 'px';
      document.getElementById('height').value = window.size().height + 'px';
    };
//-->
</script>

</body></html>

Open in new window


This is a complete page, no frameworks needed. Try resizing this window. You can do whatever you like with window.size().[width/height]. Please note that there's no default methods for getting window size that would be supported by all major browsers, so you have to use a function similar to the one you can find in the code.
0
 

Author Comment

by:areyouamac
ID: 34913380
Hey imantas!

Thank  you. This resizes the website size perfectly.

Have a great day!
0
 

Author Closing Comment

by:areyouamac
ID: 34913385
Straight to the point. Explains what to do. Thanks!
0
 

Author Comment

by:areyouamac
ID: 34913405
Hey imantas,

I have one more question,

Can this JS script also be used for ratio purposes? If, for example. the webpage has a 3/4 (height/width) ratio, how would I implement it in the coding above?

Or is it an entirely different code?

Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question