scroll-behavior-5.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!DOCTYPE HTML>
  2. <html class="reftest-wait">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Testcase for bug 1010538 - Element.ScrollLeft and Element.ScrollTop 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: 50px;
  32. height: 50px;
  33. overflow: scroll;
  34. }
  35. #scroll_2, #scroll_4 {
  36. scroll-behavior: auto;
  37. }
  38. #scroll_5, #scroll_6 {
  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. <div id="scroll_4" class="scroll_box">
  57. <div id="box4a" class="a_box"></div>
  58. <div id="box4b" class="another_box"></div>
  59. </div>
  60. <div id="scroll_5" class="scroll_box">
  61. <div id="box5a" class="a_box"></div>
  62. <div id="box5b" class="another_box"></div>
  63. </div>
  64. <div id="scroll_6" class="scroll_box">
  65. <div id="box6a" class="a_box"></div>
  66. <div id="box6b" class="another_box"></div>
  67. </div>
  68. <script>
  69. function doTest() {
  70. if (document.location.search != '?ref') {
  71. // Expect instantaneous scroll:
  72. document.getElementById("scroll_1").scrollTo({left: 0, top: 0});
  73. document.getElementById("scroll_2").scrollTo({left: 0, top: 0});
  74. document.getElementById("scroll_3").scrollTo(0, 0);
  75. document.getElementById("scroll_4").scrollTo(0, 0);
  76. // Expect smooth scroll:
  77. document.getElementById("scroll_5").scrollTo({left: 0, top: 0});
  78. document.getElementById("scroll_6").scrollTo(0, 0);
  79. // Interrupt any smooth scrolling
  80. for (var i=1; i <= 6; i++) {
  81. document.getElementById("scroll_" + i).scrollTo();
  82. }
  83. } else {
  84. // Scroll all boxes except for box5a and box6a
  85. for (var i=1; i <= 4; i++) {
  86. document.getElementById("box" + i + "a").scrollIntoView({block: "end", behavior: "instant"});
  87. }
  88. }
  89. document.documentElement.removeAttribute("class");
  90. }
  91. for (var i=1; i <= 6; i++) {
  92. document.getElementById("box" + i + "b")
  93. .scrollIntoView({block: "start", behavior: "instant"});
  94. }
  95. window.addEventListener("MozReftestInvalidate", doTest, false);
  96. </script>
  97. </body>
  98. </html>