I am working on a site where clicking on a specific link will move down the login panel. I use event.preventDefault() to stop the site redirecting, as well as an animation event, to move the panel down. When a click is clicked, the panel slides down and the URL remains unchanged.
What I want to do when I clicked the link is to animate the panel as usual, but for the href attribute of the link, which will be displayed in the URL. In this case, it will be something like this: http://domain_name/#login .
Here is the code I received right now:
$("#login_link").click(function (e) { e.preventDefault(); $("#login").animate({ 'margin-top': 0 }, 600, 'linear'); window.location.hash = $(this).attr('href'); });
This code successfully adds '#login' to the URL as desired, but it skips the login bar animation. When you click on the link, the panel immediately appears. I would like to keep both the animation and the updated url behavior. Is it possible?
javascript jquery preventdefault
Jgdev
source share