0

Hey guys i have been trying to scroll the website by adding a small piece of code to the inspect element.

The code

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>

When i add this code on the inspect element the link appear on the webpage but it doesnt scroll down ..

Hope you guys can help me ..!!!

3 Answers 3

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>

Above code is working fine.

0

On the website you got the code from it works properly.

Is something on your page goofy?

And if you're trying to scroll on somebody else's page with that (like entering it in the console), you'll have to call the pageScroll() function like this:

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

and exclude the <a href=... nonsense.

0

I always use this jQuery solution to animate a scroll. You need to add an element with an id to where you want to scroll to, and then call the function with that id

If you want you can also change the page URL and title with history.js

Html:

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

...

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

Script:

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

}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.