0

I'm trying to call a function right at the start of dragging but I can't, this div can't handle click or mousedown events on the resize icon area so I'm forced to handle it on mouseover event.

http://jsfiddle.net/PLBT6/

HTML

<div>hey</div>

CSS

div{
    width:30%;
    border:4px solid green;
    resize:horizontal;
    overflow:hidden;
}

Javascript

$("div").on("mousemove.resizer",function(e) {
    var draggingstarted = false;
    var bottom = $(this).offset().top + $(this).outerHeight();
    var right = $(this).offset().left + $(this).outerWidth();

    if (e.pageY<bottom-3 && e.pageY>bottom-16
        && e.pageX<right-3 && e.pageX>right-16){
        if (draggingstarted){
            console.log("started dragging");
        } else if (e.which==1) draggingstarted=true; //left click
        //else if (e.which==0) draggingstarted=false; //no clicks
        console.log(e.which, draggingstarted);
    }
});
shuji
  • 7,369
  • 7
  • 34
  • 49

1 Answers1

0

Ok, I made it:

http://jsfiddle.net/PLBT6/1/

var ready = false; //entered with no clicks
$("div").on("mousemove",function(e) {
    var bottom = $(this).offset().top + $(this).outerHeight();
    var right = $(this).offset().left + $(this).outerWidth();

    if (e.pageY<bottom-3 && e.pageY>bottom-16 && e.pageX<right-3 && e.pageX>right-16){
        if (e.which==1 && ready) {console.log("drag started");ready=false;} //left click
        else if (e.which==0) {console.log("ready");ready=true;} //no clicks
    } else ready=false;
});
$("div").on("mouseout",function(e) {
    ready=false;
});
shuji
  • 7,369
  • 7
  • 34
  • 49