|
1 | 1 | import React from 'react';
|
2 | 2 | import scroll from 'scroll';
|
3 | 3 | import autobind from 'react-autobind';
|
| 4 | +import { getRootEl } from './utils'; |
4 | 5 |
|
5 | 6 | import Beacon from './Beacon';
|
6 | 7 | import Tooltip from './Tooltip';
|
@@ -154,8 +155,11 @@ export default class Joyride extends React.Component {
|
154 | 155 | this.calcPlacement();
|
155 | 156 | }
|
156 | 157 |
|
157 |
| - if (state.play && props.scrollToSteps && (props.scrollToFirstStep || (state.index > 0 || prevState.index > state.index))) { |
158 |
| - scroll.top(['ie', 'firefox'].indexOf(this.getBrowser()) > -1 ? document.documentElement : document.body, this.getScrollTop()); |
| 158 | + if ( |
| 159 | + state.play && props.scrollToSteps && |
| 160 | + (props.scrollToFirstStep || (state.index > 0 || prevState.index > state.index)) |
| 161 | + ) { |
| 162 | + scroll.top(getRootEl(), this.getScrollTop()); |
159 | 163 | }
|
160 | 164 | }
|
161 | 165 |
|
@@ -387,17 +391,17 @@ export default class Joyride extends React.Component {
|
387 | 391 | const step = props.steps[state.index];
|
388 | 392 | const position = this.calcPosition(step);
|
389 | 393 | const target = document.querySelector(step.selector);
|
390 |
| - const targetTop = target.getBoundingClientRect().top + document.body.scrollTop; |
391 |
| - let scrollTop = 0; |
| 394 | + const targetTop = target.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop); |
| 395 | + let scrollTo = 0; |
392 | 396 |
|
393 | 397 | if (/^top/.test(position)) {
|
394 |
| - scrollTop = Math.floor(state.yPos - props.scrollOffset); |
| 398 | + scrollTo = Math.floor(state.yPos - props.scrollOffset); |
395 | 399 | }
|
396 | 400 | else if (/^bottom|^left|^right/.test(position)) {
|
397 |
| - scrollTop = Math.floor(targetTop - props.scrollOffset); |
| 401 | + scrollTo = Math.floor(targetTop - props.scrollOffset); |
398 | 402 | }
|
399 | 403 |
|
400 |
| - return scrollTop; |
| 404 | + return scrollTo; |
401 | 405 | }
|
402 | 406 |
|
403 | 407 | /**
|
@@ -816,8 +820,8 @@ export default class Joyride extends React.Component {
|
816 | 820 |
|
817 | 821 | return (
|
818 | 822 | <div className="joyride">
|
819 |
| - {component} |
820 |
| - {standaloneTooltip} |
| 823 | + {component} |
| 824 | + {standaloneTooltip} |
821 | 825 | </div>
|
822 | 826 | );
|
823 | 827 | }
|
|
0 commit comments