The problem is that when using the css
property, the action will be immediate. If you want it to “animate” itself (and therefore see movement on the left), you should use the animate
function with the same set of CSS properties.
$(document).ready(function() { $('#showmenu').click(function() { var hidden = $('.sidebarmenu').data('hidden'); $('#showmenu').text(hidden ? 'Show Menu' : 'Hide Menu'); if(hidden){ $('.sidebarmenu').animate({ position: 'absolute', left: -500 }, 500); } else { $('.sidebarmenu').animate({ position: 'relative', left: 0 }, 500); } $('.sidebarmenu,.image').data("hidden", !hidden); }); });
source share