Skip to content

Commit 78496f3

Browse files
committed
fix issue with position:fixed and hints
1 parent 683975a commit 78496f3

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

intro.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@
695695
elementPosition = _getOffset(currentElement.element),
696696
widthHeightPadding = 10;
697697

698+
// if the target element is fixed, the tooltip should be fixed as well.
699+
if (_isFixed(currentElement.element)) {
700+
helperLayer.className += ' introjs-fixedTooltip';
701+
}
702+
698703
if (currentElement.position == 'floating') {
699704
widthHeightPadding = 0;
700705
}
@@ -1067,7 +1072,29 @@
10671072
} else {
10681073
return propValue;
10691074
}
1070-
}
1075+
};
1076+
1077+
/**
1078+
* Checks to see if target element (or parents) position is fixed or not
1079+
*
1080+
* @api private
1081+
* @method _isFixed
1082+
* @param {Object} element
1083+
* @returns Boolean
1084+
*/
1085+
function _isFixed (element) {
1086+
var p = element.parentNode;
1087+
1088+
if (p.nodeName === 'HTML') {
1089+
return false;
1090+
}
1091+
1092+
if (_getPropValue(element, 'position') == 'fixed') {
1093+
return true;
1094+
}
1095+
1096+
return _isFixed(p);
1097+
};
10711098

10721099
/**
10731100
* Provides a cross-browser way to get the screen dimensions
@@ -1336,6 +1363,12 @@
13361363
}(hint, item, i));
13371364

13381365
hint.className = 'introjs-hint';
1366+
1367+
// hint's position should be fixed if the target element's position is fixed
1368+
if (_isFixed(item.element)) {
1369+
hint.className += ' introjs-fixedhint';
1370+
}
1371+
13391372
var hintDot = document.createElement('div');
13401373
hintDot.className = 'introjs-hint-dot';
13411374
var hintPulse = document.createElement('div');

introjs.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ tr.introjs-showElement > th {
345345
top: 50%;
346346
}
347347

348+
.introjs-fixedTooltip {
349+
position: fixed;
350+
}
351+
348352
.introjs-hint {
349353
position: absolute;
350354
background: transparent;
@@ -353,7 +357,11 @@ tr.introjs-showElement > th {
353357
}
354358

355359
.introjs-hidehint {
356-
display: none;
360+
display: none;
361+
}
362+
363+
.introjs-fixedhint {
364+
position: fixed;
357365
}
358366

359367
.introjs-hint:hover > .introjs-hint-pulse {

0 commit comments

Comments
 (0)