First half of 'if statement' in javascript is only firing once -
i have , if/else statement using resize background video, though encountering error firs half of statement if(video.style.height <= window.innerheight && fired == false) ever firing once on page resize... second half of statement, else part fire continuously, without error. there reason guys can see? i'm bit of javascript noob, sorry if obvious.
js:
window.onresize = function() { var fullwidth = window.innerwidth; var fullheight = window.innerheight; var video = document.getelementbyid("test"); var videowidth = video.style.width; var videoheight = video.style.height; console.log(videoheight); console.log(fullheight); var fired = false; if(video.style.height <= window.innerheight && fired == false) { video.style.height = fullheight + 'px'; var fullwidthadjusted = fullheight * 1.7777777; video.style.width = fullwidthadjusted + 'px'; console.log(videowidth); console.log("if statement working"); fired = true; } else { video.style.width = fullwidth + 'px'; var fullheightadjusted = fullwidth * .5625; video.style.height = fullheightadjusted + 'px'; console.log("wrong part of statement working"); fired = true; } };
i don't know if fix problem, element.style.height string in format "1234px" , window.innerheight number 1234.
edit:
instead of video.style.height try parseint(video.style.height, 10).
Comments
Post a Comment