-
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?
-
Hm, so where and when do you call these functions?
-
resizing iframe can be quite tricky. different browsers have different object to call and assign the attributes.
read from the insider : Browser Iframe
-
@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?
-
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.
-
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;