How to check if element is currently dragging

jquery, jquery-ui

Solution

Update

You can use this condition to find out if your bar is being dragged:

if ($('.bar').is('.ui-draggable-dragging')) {
    return; // bar is being dragged
}

Problem

I want to be able to check whether or not an event is occurring at the time a function is called. I have a function being called when my custom scroll bar is being dragged using .draggable() up and down and I also have a function being called when my container is scrolling. The problem is that both run at the same time which makes it act buggy. So my question is how do I do an "if" statement checking whether or not the scroll bar is currently being dragged so I can stop it from executing the rest of the function's code? I am not asking if an element has an event "binded" to it or not, but rather if that event is being triggered at a particular moment. Can I do this? Or do I need to take another approach? Here's what my code looks like: ``` $('.container').scroll(function(){ //get the heights of the container and it's contents and the difference //get the height of the scroll bar and it's container and the difference //declare the top property of scroll bar from this info }); function scrolly() { //get the heights of the elements described above //declare the scrollTop of the container } $('.bar').draggable({ axis: 'y', containment: 'parent', drag: function() { scrolly(); } }); ```

Original source