The first problem is you are loading up a queue of hover/animations bindings to .test based on your resize event binding.
Your implementation could be improved (see below) but if you want to fire a function call when resize is complete, consider the following.
var resizeTimeout;
$win.resize(function() {
clearTimeout(resizeTimeout);
// handle normal resize as needed
resizeTimeout = setTimeout(function() {
// handle after finished resize
checkwidth($win.width());
}, 250); // delay by quarter second
});
You may consider this approach:
// pull hover binding out, setup once to prevent building up queue
$(".test").hover(function() {
if( $(".test").data('annimate') ){
$(this).animate({
width: "100px"
});
}
}, function() {
if( $(".test").data('annimate') ){
$(this).animate({
width: "50px"
});
}
});
function checkwidth(mywidth) {
if (mywidth > 964) {
$body.html('Viewport is <strong>' + mywidth + 'px</strong> wide. <span class="enable">[Enable Animation]</span>');
// set flag to allow annimation
$(".test").data('annimate', true);
} else {
$body.html('Viewport is ' + mywidth + 'px wide. <span class="disable">[Disable Animation]</span>');
// set flag to prevent annimation
$(".test").data('annimate', false);
}
}