Trying to move my logo image back to its original position on window resize. I have used .prepend to move the logo originally, however it won't move back to the original position after the first prepend.
function moveLogo() {
var logo = $(".logo-wrapper");
var navTile $(".nav-tile");
var mobileBar = $(".mobile-nav-bar");
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth, //gets precise browser width
y = w.innerHeight || e.clientHeight || g.clientHeight; //gets precise height
if (x <= 587) {
logo.prependTo(mobileBar);
} else {
logo.prependTo(navTile);
}
}
window.onload = moveLogo;
window.onresize = moveLogo;
Wow, so the the post mplungjan sent me to and Vlad's recommendation made me realise what I was doing wrong. I added:
var doit;
window.onresize = function(){
clearTimeout(doit);
doit = setTimeout(moveLogo, 50);
};
This worked! I see that the way I used the javascript wasn't actually calling my function at the end of the resize event.