2013-05-14 3 views
1

jQuery를 사용하여 페이지 전환을 수행하고 있습니다. 페이지가로드 될 때 콘텐츠가 사라지고 페이드 인하지만 내 링크를 클릭하고 클릭 기능을 호출하고 리디렉션 할 때 문제가 다시 발생합니다. 페이지 맨 위에서로드하는 페이지 이 행동을 막을 수있는 방법이 있습니까? 어떤 도움을 주셔서 감사드립니다. 내 페이지 이전을위한 클릭 기능입니다.jQuery 앵커 태그를 클릭하면 페이지가 위로 이동하지 못하도록합니다.

LINK

<a href="../categories/categories.php"></a> 

jQuery를

$(".content").fadeIn(750); 

$("a").click(function(event){ 
    event.preventDefault(); 
    linkLocation = this.href; 
    $(".content").fadeOut(500, redirectPage); 
}); 

function redirectPage() { 
    window.location = linkLocation; 
} 
+1

당신이 마크 업을 제공 할 수와 함께 현재의 스크롤 위치를 캡처 할 수 있습니다, 그것은 좋은 것입니다. – vitozev

+0

마크 업의 스타일을 지정해야하는 것처럼 들립니다. 'javascript'는 정상적으로 작동합니다. –

답변

1

좋은 솔루션 : hashbangs 폴백와 역사 API를 사용

나쁜 솔루션 :당신이 어떻게 작동하는지 볼 수있는 새 바이올린을 만들 경우 쉽게 해킹 당신이

$(".content").fadeIn(750); 
    var offset = window.location.href.match(/offset=(\d+)/) 
    if(offset){ 
     $(document).scrollTop(offset[1]) 
    } 
    $("a").click(function(event){ 
     event.preventDefault(); 
     linkLocation = this.href + "?offset="+$(document).scrollTop();//pay 
//special attentions to this line will work only for a link without get parameters. 
     $(".content").fadeOut(500, redirectPage); 
    }); 

    function redirectPage() { 
     window.location = linkLocation; 
    } 
+0

고맙습니다. api 및 hashbangs를 사용하여 int를 살펴 보겠습니다.하지만 좋은 작은 해킹도 있습니다. –

관련 문제