SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: resize question

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2007
    Location
    New London, CT
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    resize question

    i need to resize two seperate div elements and each opens over an iframe. I cant quite grasp why this code doesn't work.

    Code:
    var obj1 = document.getElementById('dateInnernav');
    var obj2 = document.getElementById('hscInnerNav');
    
    function findPos(obj) {
    	var left = 0;
    	var top = 0;
    	
    	if (obj.offsetParent) {
    		left = obj.offsetLeft;
    		top = obj.offsetTop;
    		while (obj = obj.offsetParent) {
    			left += obj.offsetLeft;
    			top += obj.offsetTop;
    			}
    		}
    		return [left, top];
    	}
    	
    function rePosSiz (findPos) {
    	var width = findPos.offsetLeft;
    	var size = findPos.offsetTop;
    		if (window.clientWidth < 1024) {
    			width = this.clientWidth;
    			size = this.clientHeight;
    		}
    	}
    any suggestions?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, so where and when do you call these functions?

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    resizing iframe can be quite tricky. different browsers have different object to call and assign the attributes.

    read from the insider : Browser Iframe

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2007
    Location
    New London, CT
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Pepejeria

    i have them in the header and i am calling them like this.

    Code:
    var obj1 = document.getElementById('dateInnernav');
    var obj2 = document.getElementById('hscInnerNav');
    
    function findPos(obj) {
    	var left = 0;
    	var top = 0;
    	
    	if (obj.offsetParent) {
    		left = obj.offsetLeft;
    		top = obj.offsetTop;
    		while (obj = obj.offsetParent) {
    			left += obj.offsetLeft;
    			top += obj.offsetTop;
    			}
    		}
    		return [left, top];
    	}
    	
    function rePosSiz (findPos) {
    	var width = findPos.offsetLeft;
    	var size = findPos.offsetTop;
    		if (window.clientWidth < 1024) {
    			width = this.clientWidth;
    			size = this.clientHeight;
    		}
    	}
    
    window.onresize = rePosSiz;
    I probably should have included that, huh?

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that would have helped
    Code:
    function rePosSiz (findPos) {
    	var width = findPos.offsetLeft;
    	var size = findPos.offsetTop;
    		if (window.clientWidth < 1024) {
    			width = this.clientWidth;
    			size = this.clientHeight;
    		}
    	}
    
    window.onresize = rePosSiz;
    You are calling the rePosSiz method when the resize events triggers, which is fine, but the rePosSiz function expects a parameter that is a HTML node. The findPos function is never called in this code.

    Check the JavaScript console in Firefox, it should tell you the same thing.

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2007
    Location
    New London, CT
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so now my next question would have to be how would I call the findPos? sorry i am stumped and completely new at this. I am thinking this is what you are meaning:


    Code:
    	function findPos(obj) {
    		var left = 0;
    		var top = 0;
    		
    		if (obj.offsetParent) {
    			left = obj.offsetLeft;
    			top = obj.offsetTop;
    			while (obj = obj.offsetParent) {
    				left += obj.offsetLeft;
    				top += obj.offsetTop;
    				}
    			
    			}
    			return [left, top];
    		}
    		
    
    	function rePosSiz (id) {
    		var mnu = document.getElementById(id)
    			if (document.innerWidth < 1024 + 'px' && document.innerHeight < 768 + 'px'){
    			mnu = (document.innerWidth - 142 + 'px' * .25)
    			}
    		return findPos();
    	}
    			
    	window.onresize = rePosSiz;
    Last edited by funktifyknow; Apr 17, 2007 at 07:48. Reason: added code


Bookmarks

Posting Permissions

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