Random Scroll

0

I would like to know how to do so that at the moment you load the content of the html, the scroll ends in a random position.

the functions are these

> function scrollWin(a,b) {
>             window.scrollTo(a,b);
>         }
> 
> 
>   function aleatorio(a,b) {
>          return Math.round(Math.random()*(b-a)+parseInt(a));
>          }

and I call her with

scrollWin (aleatorio (0,0),aleatorio (500,1000))

I think of some function with the scroll, so that when loading the html it appears randomly in any position of the document.

    
asked by JelouMarra 07.11.2018 в 05:34
source

1 answer

2

This for a very specific position

window.scrollTo(x-coord, y-coord);

Or you can use the internal navigation of the document to position yourself

  • We put an element with an id

    <div id="myComponente">Hola</div>

  • By code or url we go to the position

    window.location = "#myComponente"; or http://myurl/mypath#myComponente

  • I hope it serves you, Regards !!

        
    answered by 07.11.2018 в 09:13