Javascript 通过窗口滚动网站。滚动

Javascript 通过窗口滚动网站。滚动,javascript,html,css,Javascript,Html,Css,嘿,伙计们,我一直在尝试通过向inspect元素添加一小段代码来滚动网站 代码 function pageScroll() { window.scrollBy(0,50); // horizontal and vertical scroll increments scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds } <a href="javascript:page

嘿,伙计们,我一直在尝试通过向inspect元素添加一小段代码来滚动网站

代码

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>
当我在inspect元素上添加此代码时,链接会出现在网页上,但不会向下滚动

希望你们能帮助我

<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>
上面的代码工作正常。

在屏幕上,它工作正常

你的页面上有什么东西是傻瓜吗

如果您试图在其他人的页面上滚动,就像在控制台中输入一样,您必须调用pageScroll函数,如下所示:

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

排除我总是使用这个jQuery解决方案来设置滚动动画。您需要在要滚动到的位置添加一个id为的元素,然后使用该id调用函数

如果需要,还可以使用history.js更改页面URL和标题

Html:

}

<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);

}