2014-06-23 1 views
0

안녕하세요 여러분, 저는 inspect 요소에 작은 코드 조각을 추가하여 웹 사이트를 스크롤하려했습니다.Window.Scroll을 통해 웹 사이트 스크롤하기

코드

function pageScroll() { 
    window.scrollBy(0,50); // horizontal and vertical scroll increments 
    scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds 
} 

<a href="javascript:pageScroll()">Scroll Page</a> 

내가 링크가 웹 페이지에 표시되는 요소 검사에이 코드를 추가하지만

너희들이 나를 도울 수 있기를 바랍니다 .. 아래로 스크롤 나던 때 ..!

답변

0
<html> 
<body> 
<script> 
    function pageScroll() { 
    window.scrollBy(0,50); // horizontal and vertical scroll increments 
    scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds 
    } 
</script> 
<a href="javascript:pageScroll()">Scroll Page</a> 
    <p>some really large content for scrolling ....</p> 
</body> 
</html> 

위의 코드는 정상적으로 작동합니다.

0

website you got the code from에서 제대로 작동합니다.

페이지에 뭔가 이상한 것이 있습니까?

function pageScroll() { 
//code 
} 
pageScroll(); 

및 제외 : (콘솔에서 입력과 같은) 그와 누군가 다른 사람의 페이지에 을 이동하려는 경우

, 당신은이 같은 pageScroll() 함수를 호출해야합니다 <a href=... 난센스.

0

난 항상이 애니메이션을 사용하여이 jQuery 솔루션을 사용한다. 당신은 그 ID로 기능을 사용자가 스크롤 할 위치에 ID를 가진 요소를 추가 한 후 호출 할 필요가 당신은 또한 history.js

HTML을 사용하여 페이지의 URL 및 제목을 변경할 수 있습니다 원하는 경우

:

<a href="javascript:ScrollToHash('content');">Scroll to panel</a> 

... 

<div id="content" data-title="Page title here"> 

스크립트 :

function ScrollToHash(hash) { 

var id = hash.replace('#', ''); 

if ($('#' + id).length > 0) { 

    var top = $('#' + id).offset().top; 

    if (id == "home") { top = 0; } 

    $('html, body').animate({ 
      scrollTop: top 
    }, 500, function() { // do something on complete function }); 

// Optional: Change page URL and title with history.js 
    var ttl = $('#' + id).attr("data-title") + ' - Marbles'; 
    History.pushState(null, ttl, $('#' + id).attr("data-page-url")); 
    $("title").text(ttl); 

} 

}

관련 문제