I have two images. I am trying to display one when the browser resizes left, and the other when it resizes right.
function adjustDirection() {
var last_pos_x = window.screenX;
if ( last_pos_x < window.screenX) {
document.getElementById("logo").style.backgroundImage = "url('logoRight.png')";
} else if (last_pos_x > window.screenX) {
document.getElementById("logo").style.backgroundImage = "url('logoLeft.png')";
}
}
window.onresize = adjustDirection;
However, it seems like my function only begins to works if last_pos_x
is declared outside of the function, which is clearly wrong because it will only store window.screenX
from load.
Any help would be greatly appreciated