Solved

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

Posted on 2011-02-16
4
869 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

739 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