JavaScript
- 7 ответов
- 0 вопросов
4
Вклад в тег
var waitForFinalEvent = (function () {
var timers = {};
return function (callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Don't call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout (timers[uniqueId]);
}
timers[uniqueId] = setTimeout(callback, ms);
};
})();
$(window).resize(function () {
waitForFinalEvent(function(){
alert('Resize...');
//...
}, 500, "some unique string");
});
var isEvent = false;
$( window ).on( 'resize', function() {
if ( !isEvent ) {
// this my code
isEvent = true;
setTimeout( function() {
isEvent = false;
}, 1000 );
}
} )