Skip to content

Commit 10e58cf

Browse files
committed
Merge pull request usablica#227 from peterkinmond/master
Allow scolling to element to be set as option
2 parents 1b01373 + 0820b4d commit 10e58cf

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
@@ -279,6 +279,7 @@ introJs().onbeforechange(function(targetElement) {
279279
- `keyboardNavigation`: Navigating with keyboard or not, `true` or `false`
280280
- `showButtons`: Show introduction navigation buttons or not, `true` or `false`
281281
- `showBullets`: Show introduction bullets or not, `true` or `false`
282+
- `scrollToElement`: Autoscoll to highlighted element, `true` or `false`
282283

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

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
@@ -420,7 +422,7 @@
420422
skipTooltipButton = oldHelperLayer.querySelector('.introjs-skipbutton'),
421423
prevTooltipButton = oldHelperLayer.querySelector('.introjs-prevbutton'),
422424
nextTooltipButton = oldHelperLayer.querySelector('.introjs-nextbutton');
423-
425+
424426
//hide the tooltip
425427
oldtooltipContainer.style.opacity = 0;
426428

@@ -451,7 +453,7 @@
451453
oldtooltipLayer.innerHTML = targetElement.intro;
452454
//set the tooltip position
453455
_placeTooltip.call(self, targetElement.element, oldtooltipContainer, oldArrowLayer);
454-
456+
455457
//change active bullet
456458
oldHelperLayer.querySelector('.introjs-bullets li > a.active').className = '';
457459
oldHelperLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
@@ -480,7 +482,7 @@
480482

481483
tooltipTextLayer.className = 'introjs-tooltiptext';
482484
tooltipTextLayer.innerHTML = targetElement.intro;
483-
485+
484486
bulletsLayer.className = 'introjs-bullets';
485487

486488
if (this._options.showBullets === false) {
@@ -622,7 +624,7 @@
622624
parentElm = parentElm.parentNode;
623625
}
624626

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

0 commit comments

Comments
 (0)