Use JQuery preventDefault(), but still add the path to the URL

混江龙づ霸主 提交于 2019-12-05 01:29:00

use below code . just call the hash in animation completed event.

$("#login_link").click(function (e) {
    e.preventDefault();
    $("#login").animate({ 'margin-top': 0 }, 600, 'linear', function(){  window.location.hash = $(this).attr('href'); });

});

I am not sure but you may bee looking for this feature

1> when some body clicks login, url changes to abc.com/#login, and login panel animation occurs

or

2 > when some body just types abc.com/#login in url, you expect the same behavior (animation of login panel).

What you are doing currently will work only for case1 and wont work for case2. If you want animation (or whatever) to work both, when clicked , or just url typed. You need some mechanism to detect hash changes.

There is a famous plugin http://benalman.com/projects/jquery-bbq-plugin/

Go and see this plugin and, look how things are done. If you find anything tough to understand we are here!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!