Dr. Morpheus Dr. Morpheus - 3 months ago 9
CSS Question

Jquery for CSS attribute change with ease and return on place again

I am trying to open left slidepanel here is the code

jQuery('.right_panel_handle').on('click',function() {
jQuery('.right_panel').css({'right':'0px'});
return false;
});


I am trying to change position on click with ease and upon click again it should return to its place.

Need help please!

Answer
jQuery('.right_panel_handle').on('click',function() {
    var panel = jQuery('.right_panel');
    if (panel.offset().left > $(window).width() - panel.width()){
        panel.css('right', '0px');
    } else {
        panel.css('right', - panel.width() + 'px');
    }
    return false;
});
Comments