scroll-behavior-4.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE HTML>
  2. <html class="reftest-wait">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Testcase for bug 1010538 - Anchor Link Scrolling</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. display: inline-block;
  30. }
  31. .scroll_box {
  32. width: 50px;
  33. height: 50px;
  34. overflow: scroll;
  35. will-change: scroll-position;
  36. }
  37. #scroll_1 {
  38. scroll-behavior: auto;
  39. }
  40. #scroll_3 {
  41. scroll-behavior: smooth;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div id="scroll_1" class="scroll_box">
  47. <div id="box1a" class="a_box"></div>
  48. <a name="test_anchor_1" id="box1b" class="another_box"></a>
  49. </div>
  50. <div id="scroll_2" class="scroll_box">
  51. <div id="box2a" class="a_box"></div>
  52. <a name="test_anchor_2" id="box2b" class="another_box"></a>
  53. </div>
  54. <div id="scroll_3" class="scroll_box">
  55. <div id="box3a" class="a_box"></div>
  56. <a name="test_anchor_3" id="box3b" class="another_box"></a>
  57. </div>
  58. <script>
  59. function doTest() {
  60. if (document.location.search != '?ref') {
  61. // Scroll_1 to Scroll_2 are expected to scroll instantly
  62. window.location.hash = "test_anchor_1";
  63. window.location.hash = "test_anchor_2";
  64. // Scroll_3 is expected to scroll smoothly
  65. document.getElementById("box3b").scrollIntoView({block: "end", behavior: "smooth"});
  66. // Interrupt any smooth scrolling
  67. for (var i=1; i <= 3; i++) {
  68. document.getElementById("scroll_" + i).scrollLeft
  69. = document.getElementById("scroll_" + i).scrollLeft;
  70. document.getElementById("scroll_" + i).scrollTop
  71. = document.getElementById("scroll_" + i).scrollTop;
  72. }
  73. } else {
  74. // Scroll all boxes except for Scroll_3
  75. for (var i=1; i <= 2; i++) {
  76. document.getElementById("box" + i + "b").scrollIntoView({block: "end", behavior: "instant"});
  77. }
  78. }
  79. document.documentElement.removeAttribute("class");
  80. }
  81. for (var i=1; i <= 3; i++) {
  82. document.getElementById("box" + i + "a")
  83. .scrollIntoView({block: "start", behavior: "instant"});
  84. }
  85. window.addEventListener("MozReftestInvalidate", doTest, false);
  86. </script>
  87. </body>
  88. </html>