Guest User

Untitled

a guest
Sep 10th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>Backspace/Enter -> PageUp/Down testi</title>
  6.         <script>
  7.             window.onload = () => {
  8.                 document.addEventListener('keydown', (e) => {
  9.                     if(e.key == 'Enter') {
  10.                         window.scrollBy(0, window.innerHeight);
  11.                     }
  12.                     if(e.key == 'Backspace') {
  13.                         window.scrollBy(0, -window.innerHeight);
  14.                     }
  15.                     if(e.key == 'ArrowDown') {
  16.                         document.dispatchEvent(new KeyboardEvent('keydown',{'key': 'Enter'}));
  17.                     }
  18.                     if(e.key == 'ArrowUp') {
  19.                         document.dispatchEvent(new KeyboardEvent('keydown',{'key': 'Backspace'}));
  20.                     }
  21.                 });
  22.                 const listaElementti = document.getElementById('lista');
  23.                 for(let i=1; i<=100; i++) {
  24.                    const uusiElementti = document.createElement('li');
  25.                    uusiElementti.innerHTML = 'Listaelementti '+i;
  26.                    listaElementti.appendChild(uusiElementti);
  27.                }
  28.            };
  29.        </script>
  30.     </head>
  31.     <body>
  32.         <h1>Backspace/Enter -> PageUp/Down testi</h1>
  33.         <p>Backspace / ArrowUp vierittää sivun verran ylös</p>
  34.         <p>Enter / ArrowDown vierittää sivun verran alas</p>
  35.         <ul id="lista"></ul>
  36.     </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment