Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-16
4
Medium Priority
?
879 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

705 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