how its do to open a web page not at 100% of screen whit html? | Sololearn: Learn to code for FREE!
+ 2

how its do to open a web page not at 100% of screen whit html?

in my code sans i want to open the fight only at a certain % of the page bur i didnt know how https://code.sololearn.com/Wx0knQbhJvm3/?ref=app

19th Mar 2021, 1:00 PM
Chr1st12n
Chr1st12n - avatar
2 Answers
+ 1
Igor Makarsky you could workaround the code playground limitation by using setTimeout with some (unnoticeable) delay: onload = () => setTimeout(window.scrollBy.bind(window),50,0,300); even if I guess that Chr1st12n ask for % of page as scale... if not, it deserve mentionning that scrollBy get x and y (horizontal and vertical) scroll amount in pixel... also, that setTimeout takes a callback function as argument, followed by optional delay in milliseconds, and followed by optional arguments to pass to callback when called. and that as scrollby is a method of window object or html element object, you must bind it to not loose the 'this' context value ^^
22nd Mar 2021, 10:43 PM
visph
visph - avatar
+ 7
Do you mean scroll position or scale? If you want to change scroll position when a page is loaded then, unfortunately, you can't do it only with HTML. You need JavaScript. The following code does the trick: window.onload = () => window.scrollBy (0, 300); All values are in pixels. It scrolls 0px right and 300px down. But there's a limitation: for some reason it doesn't work in the Code Playground.
22nd Mar 2021, 10:26 PM
Igor Makarsky
Igor Makarsky - avatar