jQuery Delayed Scroll Execution

A snippet to delay code execution until the user has stopped scrolling for a set period or time.

HTML

<div style="height:2000px;">
<div id="id1" style="position:fixed;top:0;left:0;">
asdqq
</div>
</div>

JavaScript

var scrolled = true;

$(window).scroll(function() {
	if(scrolled){
			yourFunction()
  }
});


var i = 0;
function yourFunction() {
  scrolled = false;
 		setInterval(function () {
            hasScrolled();
            scrolled = true;
    }, 1000);
}
function hasScrolled(){
	var id1 = document.getElementById("id1");
  id1.innerText="qq"+i;
  i++;
}