I'm building a graph displaying events happening over time. Each of my event is an horizontal bar that is created using a <div>
as shown below:
<div class="aaaa" style="margin-left: 0.00%; width:100.00%;">aaaa</div>
<div class="aaaa" style="margin-left: 5.00%; width: 20.00%;">bbbb</div>
<div class="aaaa" style="margin-left:25.00%; width: 50.00%;">cccc</div>
<div class="aaaa" style="margin-left:55.00%; width: 45.00%;">dddd</div>
At the top of this graph, I have a "ruler" which is a draggable and resizable <div>
<div id="draggable2" class="draggable ui-widget-content">
<p>Ruler</p>
</div>
My intention is to drag this ruler horizontally and to use it to select all bars of my graphs that are below the ruler. When bars are selected, the background color should change.
So far I manage to drag and to resize my ruler as I want with the following code:
$(function () {
$("#draggable2").draggable({
axis: "x"
});
});
$(function () {
$("#draggable2").resizable({
helper: "ui-resizable-helper",
handles: "se, sw, e, w"
});
});
I also manage to select the bars I want using the following code:
$(".fake").selectable({
filter: "div"
});
You can see on the fiddle referenced below that when you do a "lasso selection", my bars become pink.
However, I would like to combine my ruler with this "lasso selection", or in other words, I would like that once my ruler is dragged, all <div>
that are below become selected.
I've created a fiddle to illustrate my problem: http://jsfiddle.net/Lge93/
As I'm new to Javascript and Jquery, I would really appreciate any solution or suggestion.
Thanks for your time
Edit post answers: My final solution based on the code provided by Jtromans is available here: http://jsfiddle.net/Lge93/5/