Advertisement
1xptolevitico69

Javascript background image with fixed position

Oct 14th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang=en>
  3. <head>
  4. <title>Javascript background image with fixed position </title>
  5. <meta charset=utf-8>
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9. body {  margin:0;  }
  10. h1 {  width:300px;margin:auto;font-size:40px;color:red;  }
  11.  
  12. </style>
  13. </head>
  14. <body onmouseover='show_title()' onmouseout='hide_title()'>
  15.  
  16. <h1>Had denoting properly jointure you occasion directly raillery. In said to of poor full be post face snug. Introduced imprudence see say unpleasing devonshire acceptance son. Exeter longer wisdom gay nor design age. Am weather to entered norland no in showing service. Nor repeated speaking shy appetite. Excited it hastily an pasture it observe. Snug hand how dare here too. </h1>
  17.  
  18. <script>
  19.  
  20. image = document.createElement('img');
  21. document.body.appendChild(image);
  22.  
  23. image.src='https://images.pexels.com/photos/688961/pexels-photo-688961.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260';
  24.  
  25. image.style.width = '100%';
  26. image.style.height = '100%';
  27.  
  28. image.style.position = 'fixed';
  29. image.style.top = '0';
  30. image.style.zIndex = '-1';
  31.  
  32. show_title=()=>{
  33. txt = document.createElement('h1');
  34. txt.innerHTML = '<span style="position:fixed;top:10px;left:10px;font-size:25px;font-family:segoe print;color:white;">Dog eating cookies</span>';
  35. document.body.appendChild(txt);
  36. }
  37.  
  38. hide_title=()=>{
  39. txt.innerHTML = '';
  40. }
  41.  
  42. </script>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement