Here I take care of this problem. It works on the clock, but itβs easy enough to adapt to the step in half an hour or fifteen minutes.
HTML:
<div id="hours"> <div class="hour">8am</div> <div class="hour">9am</div> <div class="hour">10am</div> <div class="hour">11am</div> <div class="hour">...</div> </div>
Javascript:
var dragging; var yOnMousedown; $('.hour').mousedown( function(e) { e.preventDefault(); $(this).addClass( 'hour-highlighted' ); dragging = true; yOnMousedown = e.pageY; } );βββ $(document).mouseup( function(e) { e.preventDefault(); dragging = false; } ); $(document).mousemove( function(e) { if( dragging ) { e.preventDefault(); $('.hour').each( function() { var top = $(this).offset().top; var bottom = top + $(this).height(); if( bottom > yOnMousedown && e.pageY > top ) $(this).addClass( 'hour-highlighted' ); else $(this).removeClass( 'hour-highlighted' ); } ); } } );
jsfiddle here: http://jsfiddle.net/cv9LM/
source share