Can a handler be connected to a slip event?

Is it possible to listen for a sliding event on a specific element?

I was hoping this would be easy:

 $("#element").slideDown();

 $('#element').bind('slideDown', function() {  
    alert('Slidedown event fired');  
 });

Could not find "slideDown" as event .

Is listening to such an event possible?

+3
source share
2 answers

To do this, I simply add more semantic methods. Therefore, if you have a menu and you want to trigger an event when you crawl it, instead do something like

var menu = $('#menu');
menu.open = function() {
  menu.slideDown();
  menu.trigger('menuOpened');
};

menu.open() menu.slideDown(). , , . , (, fadeIn - ), , .

+3

, :

$(function(){
    ;(function($){
        var orig_slideDown = $.fn.slideDown;

        $.fn.slideDown = function(){
            $(this).trigger('slideDown');
            orig_slideDown.apply(this, arguments);
        };
    })(jQuery);

    $('.up').click(function(){
        $('div').slideUp();
    });
    $('.down').click(function(){
        $('div').slideDown();
    });
    $('div').bind('slideDown',function(){
        $('div').append($('<p>').text('Down Triggered'));
    });
});

<a href="#" class="up">Up</a> <a href="#" class="down">Down</a>
<div style="width:300px;height:200px;background-color:red;color:white;">
    <p>Hello, world!</p>
</div>
0

Source: https://habr.com/ru/post/1786849/


All Articles