Skip to content

Commit 0820b4d

Browse files
committed
Allow scolling to element to be set as option
* Auto-scrolling isn't always the user experience you want. Allow it to be turned off.
1 parent 4f20edc commit 0820b4d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ introJs().onbeforechange(function(targetElement) {
270270
- `keyboardNavigation`: Navigating with keyboard or not, `true` or `false`
271271
- `showButtons`: Show introduction navigation buttons or not, `true` or `false`
272272
- `showBullets`: Show introduction bullets or not, `true` or `false`
273+
- `scrollToElement`: Autoscoll to highlighted element, `true` or `false`
273274

274275
See [setOption](https://github.com/usablica/intro.js/#introjssetoptionoption-value) to see an example.
275276

intro.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
/* Show tour control buttons? */
5454
showButtons: true,
5555
/* Show tour bullets? */
56-
showBullets: true
56+
showBullets: true,
57+
/* Scroll to highlighted element? */
58+
scrollToElement: true
5759
};
5860
}
5961

@@ -116,7 +118,7 @@
116118
var currentElement = allIntroSteps[i];
117119

118120
if (currentElement.getAttribute('data-step') == null) {
119-
121+
120122
while (true) {
121123
if (typeof introItems[nextStep] == 'undefined') {
122124
break;
@@ -141,7 +143,7 @@
141143
for (var z = 0; z < introItems.length; z++) {
142144
introItems[z] && tempIntroItems.push(introItems[z]); // copy non-empty values to the end of the array
143145
}
144-
146+
145147
introItems = tempIntroItems;
146148

147149
//Ok, sort all items with given steps
@@ -418,7 +420,7 @@
418420
skipTooltipButton = oldHelperLayer.querySelector('.introjs-skipbutton'),
419421
prevTooltipButton = oldHelperLayer.querySelector('.introjs-prevbutton'),
420422
nextTooltipButton = oldHelperLayer.querySelector('.introjs-nextbutton');
421-
423+
422424
//hide the tooltip
423425
oldtooltipContainer.style.opacity = 0;
424426

@@ -449,7 +451,7 @@
449451
oldtooltipLayer.innerHTML = targetElement.intro;
450452
//set the tooltip position
451453
_placeTooltip.call(self, targetElement.element, oldtooltipContainer, oldArrowLayer);
452-
454+
453455
//change active bullet
454456
oldHelperLayer.querySelector('.introjs-bullets li > a.active').className = '';
455457
oldHelperLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
@@ -478,7 +480,7 @@
478480

479481
tooltipTextLayer.className = 'introjs-tooltiptext';
480482
tooltipTextLayer.innerHTML = targetElement.intro;
481-
483+
482484
bulletsLayer.className = 'introjs-bullets';
483485

484486
if (this._options.showBullets === false) {
@@ -620,7 +622,7 @@
620622
parentElm = parentElm.parentNode;
621623
}
622624

623-
if (!_elementInViewport(targetElement.element)) {
625+
if (!_elementInViewport(targetElement.element) && this._options.scrollToElement === true) {
624626
var rect = targetElement.element.getBoundingClientRect(),
625627
winHeight=_getWinSize().height,
626628
top = rect.bottom - (rect.bottom - rect.top),

0 commit comments

Comments
 (0)