mousedrag event

by Amine Tbaik

HTML

<div></div>

CSS

div{
  background: lightblue;
  width: 100px;
  height: 100px;
}

JavaScript

$.fn.mousedrag = function(f){
	let mousedown = false
	$(this).mousedown(function(){
  	mousedown = true
  }).mousemove(function(){
  	if(mousedown){
    	mousedown = false
    	f()
    }
  })
}
$('div').mousedrag(function(){
	alert('dragged')
})