2016-10-05 2 views
0

이 내 메뉴 바의 jQuery 스크롤 (노드 EJS)의

<ul id="jump" class="dropdown-menu" role="menu"> 
     <li><a href="/main_page#top_something">People</a></li> 
     <li><a href="/main_page">Main Page</a></li> 
    </ul> 

이고 I는이 기능

(function($){ 

var jump=function(e) 
{ 
    if (e){ 
     e.preventDefault(); 
     var target = $(this).attr("href"); 
    }else{ 
     var target = location.hash; 
    } 

    $('html,body').animate(
    { 
     scrollTop: $(target).offset().top 
    },1000,function() 
    { 
     location.hash = target; 
    }); 

} 

$('html, body').hide() 

$(document).ready(function() 
{ 
    $('#jump a[href]').bind("click", jump); 

    if (location.hash){ 
     setTimeout(function(){ 
      $('html, body').scrollTop(0).show() 
      jump() 
     }, 0); 
    }else{ 
     $('html, body').show() 
    } 
}); 

}) (jQuery를)

사용하고

main_page은 ejs 파일이며 /main_page 경로에 node.js가 표시됩니다. main_page.ejs 파일.

페이지의 navbar를 클릭하고 div 섹션의 B 페이지로 이동하려고합니다. 이 나를 제공 : jump.js : 18 catch되지 않은 형식 오류 : 정의되지 않은 오류의 특성 '최고'를 읽을 수 없습니다를 여기

가 동일한 주제, jQuery scroll to ID from different page하지만 난이 작동 얻을 수 없다 ... 덕분에

차이가 나는 Node.js를이 있고 * 파일

+0

에 나를 위해 일한 무엇을 .ejs이다 g nodejs 정적'.html' 파일로 라우팅하지 않는다고 가정합니다. 경로는 어떻게 정의되어 있습니까? –

+0

app.get ('/ main_page', 기능 (REQ, 고해상도, 다음) { res.render ('main_page', {제목 : '뭔가', headerTitle 'sometnig1', 사용자 ID : req.session. 사용자 ID}); 이고 main_page는 .ejs 파일입니다. – katrin

답변

0
(function(){ 
    if(location.hash === '#top_something'){ 
     window.setTimeout(
     function(){ 
      $('html, body').animate({ 
      scrollTop: $('#top_something').offset().top 
      }, 'slow'); 
     },2000); 
    } 
})(); 

이것은 당신이저기서하는 경우이 경우 :