내 홈페이지에 ID가있는 메뉴가 있습니다.이 메뉴를 클릭하면 해당 div로 슬라이드되고 부드럽게 작동합니다.URL에서 ID로 천천히 이동하십시오.
하지만 내 홈페이지에 있지 않을 때 항목을 클릭하면 홈페이지로 이동 한 다음 섹션으로 이동할 수 있기를 원합니다. 이 우수한 작동
$('#mainMenu a').click(function(e){
e.preventDefault();
var div = $(this).attr('href');
if('<?=get_site_url()?>/' == '<?=get_permalink()?>')
{
$('html, body').animate({scrollTop:$(div).position().top}, 'slow');
}
else
{
window.location.href = '<?=get_site_url()?>/'+div;
}
});
, 다음 부분에 작동하지만 나는 그것이 ID에 미끄러 얻을 수 : 여기
내가 지금 사용하고 코드입니다.if (window.location.hash != "") {
e.preventDefault();
$('html, body').animate({scrollTop:$(window.location.hash).position().top}, 'slow');
}
브라우저가 섹션으로 바로 이동하지 못하도록 방지 할 수있는 방법이 있습니까?
http://stackoverflow.com/questions/3503559/prevent-default-hash-behavior-on-page - – thefrontender