Check this Fiddle
if (!$(".box2").hasClass("animated")) {
if (wdt >= 60) {
$(".box2").animate({
width: '350px'
}, 2000);
$(".box2").addClass('animated');
}
} else {
if (wdt <= 350) {
$(".box2").css('width','60px');
$(".box2").removeClass('animated');
}
}
side note: not sure if this is exactly what you want, if not comment below :)
update as per comments updated fiddle
$(document).ready(function () {
anime();
var resizeTimer;
window.onresize = function () {
if (resizeTimer) {
clearTimeout(resizeTimer);
}
resizeTimer = setTimeout(function () {
anime();
}, 200);
}
})
function anime() {
var windowWidth = $(window).width();
var box1width = $(".box1").width();
var wdt = windowWidth - (box1width);
if (wdt > 60) {
$(".box2").stop(true,true).animate({
width: wdt
}, 1000);
$(".box2").addClass('animated');
} else if($(".box2").hasClass('animated')){
$(".box2").css('width', '60px');
$(".box2").removeClass('animated');
}
}
Note: this is just a fix for what you're trying to do, i'd prefer css3 transition over this..