www.webdeveloper.com
Results 1 to 3 of 3

Thread: Error styling in js

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Error styling in js

    Hello everyone, guys

    I've been having some trouble with styling an element in my page. Can any of u see the problem?

    HTML Code:
    <html>
    	<head>
        	<script type="text/javascript">
    			function Window() {
    				this._getY = function() {
    					return(window.innerHeight);
    				}
    				this._getX = function() {
    					return(window.innerWidth);
    				}
    				this._load = function() {
    					var w = document.getElementById("window");
    						w.style.width = this._getX();
    						w.style.height = this._getY();
    				}
    			}
    			var WINDOW = new Window();
    			WINDOW._load();
    		</script>
            <style type="text/css">
    			#window {
    				display: block;
    				position: absolute;
    				top: 0px;
    				left: 0px;
    				background-color:red;
    			}
    		</style>
        </head>
        <body>
        	<div id="window">
            	Content 
            </div>
        </body>
    </html>
    I have tryed to alert the methods _getX() and _getY(), and both functions are working pretty. I think the problem it's on the styling thing, or getting the element on the page.

    Maybe there's a simple error that I'm not seeing, i've spent too much time using Jquery, so probably I got too confortable on that.

    Sorry for my bad english, it's not my native language.
    Thank you all

  2. #2
    Join Date
    Jul 2011
    Posts
    131
    You should create your object after all assets will be downloaded.
    It is working code:
    Code:
    window.onload = function(){
        var WINDOW = new Window();
        WINDOW._load();			
    }

  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Thanks, kromol

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles