scroll-behavior-8.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE HTML>
  2. <html class="reftest-wait">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Testcase for bug 1010538 - Dynamically change scroll-behavior</title>
  6. <style type="text/css">
  7. html,body {
  8. color: black;
  9. background-color: white;
  10. font-size: 16px;
  11. padding: 0;
  12. margin: 0;
  13. }
  14. .a_box {
  15. position: relative;
  16. left: 0px;
  17. top: 0px;
  18. width: 20px;
  19. height: 20px;
  20. background: blue;
  21. }
  22. .another_box {
  23. position: relative;
  24. left: 2000px;
  25. top: 2000px;
  26. width: 20px;
  27. height: 20px;
  28. background: green;
  29. }
  30. .scroll_box {
  31. width: 150px;
  32. height: 150px;
  33. overflow: scroll;
  34. }
  35. #scroll_2 {
  36. scroll-behavior: auto;
  37. }
  38. #scroll_3 {
  39. scroll-behavior: smooth;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div id="scroll_1" class="scroll_box">
  45. <div id="box1a" class="a_box"></div>
  46. <div id="box1b" class="another_box"></div>
  47. </div>
  48. <div id="scroll_2" class="scroll_box">
  49. <div id="box2a" class="a_box"></div>
  50. <div id="box2b" class="another_box"></div>
  51. </div>
  52. <div id="scroll_3" class="scroll_box">
  53. <div id="box3a" class="a_box"></div>
  54. <div id="box3b" class="another_box"></div>
  55. </div>
  56. <script>
  57. function doTest() {
  58. if (document.location.search != '?ref') {
  59. // Expect smooth scroll:
  60. document.getElementById("scroll_1").style.scrollBehavior = "smooth";
  61. document.getElementById("scroll_1").scrollTo({left: 0, top: 0});
  62. document.getElementById("scroll_2").style.scrollBehavior = "smooth";
  63. document.getElementById("scroll_2").scrollTo({left: 0, top: 0});
  64. // Expect instant scroll:
  65. document.getElementById("scroll_3").style.scrollBehavior = "auto";
  66. document.getElementById("scroll_3").scrollTo({left: 0, top: 0});
  67. } else {
  68. document.getElementById("scroll_1").scrollTo({left: 0, top: 0, behavior: "smooth"});
  69. document.getElementById("scroll_2").scrollTo({left: 0, top: 0, behavior: "smooth"});
  70. document.getElementById("scroll_3").scrollTo({left: 0, top: 0, behavior: "instant"});
  71. }
  72. // Interrupt any smooth scrolling
  73. for (var i=1; i <= 3; i++) {
  74. document.getElementById("scroll_" + i).scrollTo();
  75. }
  76. document.documentElement.removeAttribute("class");
  77. }
  78. for (var i=1; i <= 3; i++) {
  79. document.getElementById("box" + i + "b")
  80. .scrollIntoView({block: "start", behavior: "instant"});
  81. }
  82. window.addEventListener("MozReftestInvalidate", doTest, false);
  83. </script>
  84. </body>
  85. </html>