scroll.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <p>
  2. <button id="scrollToBlue">Go to blue</button>
  3. </p>
  4. <div id="target-blue" class="test-box">
  5. <div class="test-box">
  6. <div class="test-box">
  7. <div class="target">
  8. <button>Go to red</button>
  9. </div>
  10. </div>
  11. </div>
  12. </div>
  13. <div id="target-red" class="test-box">
  14. <div class="test-box">
  15. <div class="test-box">
  16. <div class="target">
  17. <button>Go to green</button>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <div id="target-green" class="test-box">
  23. <div class="test-box">
  24. <div class="test-box">
  25. <div class="target">
  26. <button>Go to blue</button>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <style>
  32. body {
  33. height: 2000px;
  34. width: 2000px;
  35. }
  36. body > .test-box {
  37. position: absolute;
  38. }
  39. .test-box {
  40. background: #fff;
  41. padding: 15px;
  42. border: 25px solid #eee;
  43. overflow: scroll;
  44. position: relative;
  45. }
  46. .test-box > .test-box {
  47. margin-top: 1000px;
  48. margin-bottom: 1000px;
  49. height: 400px;
  50. width: 400px;
  51. }
  52. .test-box > .test-box > .test-box {
  53. height: 800px;
  54. width: 800px;
  55. }
  56. .target {
  57. width: 80px;
  58. height: 80px;
  59. position: absolute;
  60. bottom: 0;
  61. right: 0;
  62. color: #fff;
  63. }
  64. #target-blue .target {
  65. background: blue;
  66. }
  67. #target-red .target {
  68. background: red;
  69. }
  70. #target-green .target {
  71. background: green;
  72. }
  73. #target-blue,
  74. #target-red,
  75. #target-green {
  76. width: 100px;
  77. height: 100px;
  78. }
  79. #target-blue {
  80. left: 1500px;
  81. top: 1500px;
  82. }
  83. #target-red {
  84. left: 1200px;
  85. top: 100px;
  86. }
  87. #target-green {
  88. left: 500px;
  89. top: 1300px;
  90. }
  91. </style>