How to scroll automatico for a distance from the top without anchoring Wordpress

Asked

Viewed 184 times

1

Well I’ve researched enough, I’ve seen several tutorials on how to make a scroll via anchorage, however I search a scroll for all pages including the initial, I searched some plugins in Wordpress as for example: scroll in id, but everyone I’ve found fulfills the same action leading me to a particular id...

I need to get the distance to the top of 400, if it was possible to make track jquery would do so:

$("body").scrollTop(400);

But how to do it in Wordpress?

1 answer

0


From what I understand you want when entering the page it scrolls 400px. If that’s it you can use the code below. I also includes a scroll-behavior: smooth; for the scrolling to be a little slower. But if you don’t want this effect just strip the CSS.

Just click on Run below to see working

$(document).ready(function(){
    $(this).scrollTop(400);
});
html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background-image: linear-gradient(to bottom, #f00 0%, #00f 100%);
    height: 200vh;
}
html {
  scroll-behavior: smooth;
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

Similar answer on the English website with other jQuery code options

  • But how do I add it in wordpress? I tried to add directly to the font failed.

  • Does your WP already have jQuery? I believe it is within Function.PHP or HEAD, it depends on each Theme... If you have access to Footer.php put inside the footer that is ideal. If you can go to the documentation of the theme you are using and search for how to add extra scripts

Browser other questions tagged

You are not signed in. Login or sign up in order to post.