Solved

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

Posted on 2011-02-16
4
853 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
Comment Utility
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
Comment Utility
Hey imantas!

Thank  you. This resizes the website size perfectly.

Have a great day!
0
 

Author Closing Comment

by:areyouamac
Comment Utility
Straight to the point. Explains what to do. Thanks!
0
 

Author Comment

by:areyouamac
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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 embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now