2017.04.17-parallax.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. html, body {
  5. max-width: 100%;
  6. overflow: hidden;
  7. }
  8. #bg {
  9. width: 300%;
  10. }
  11. #human {
  12. bottom: -30px;
  13. }
  14. * {
  15. margin: 0;
  16. padding: 0;
  17. }
  18. video {
  19. margin-left: -10px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <script>
  25. function setX(el, mouse, amount) {
  26. var width = document.body.clientWidth;
  27. el.style.position = 'absolute';
  28. el.style.left = width/2 - amount*(width/2-mouse) - el.clientWidth/2;
  29. }
  30. document.onmousemove = function(e) {
  31. var human = document.getElementById('human');
  32. var bg = document.getElementById('bg');
  33. setX(bg, e.pageX, 0.25);
  34. setX(human, e.pageX, 0.5);
  35. }
  36. </script>
  37. <div>
  38. <div id="bg">
  39. <video src="rectface.webm" autoplay loop></video>
  40. <video src="rectface.webm" autoplay loop></video>
  41. <video src="rectface.webm" autoplay loop></video>
  42. </div>
  43. <video id="human" src="fight.webm" autoplay loop></video>
  44. </div>
  45. </body>
  46. </html>