From 78496f3a7c6f9e0ca25ac2fe907e14529e610261 Mon Sep 17 00:00:00 2001 From: Afshin Mehrabani Date: Sun, 20 Dec 2015 15:43:43 +0330 Subject: [PATCH] fix issue with position:fixed and hints --- intro.js | 35 ++++++++++++++++++++++++++++++++++- introjs.css | 10 +++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/intro.js b/intro.js index e3fd8cf1c..b9aa4bc4c 100644 --- a/intro.js +++ b/intro.js @@ -695,6 +695,11 @@ elementPosition = _getOffset(currentElement.element), widthHeightPadding = 10; + // if the target element is fixed, the tooltip should be fixed as well. + if (_isFixed(currentElement.element)) { + helperLayer.className += ' introjs-fixedTooltip'; + } + if (currentElement.position == 'floating') { widthHeightPadding = 0; } @@ -1067,7 +1072,29 @@ } else { return propValue; } - } + }; + + /** + * Checks to see if target element (or parents) position is fixed or not + * + * @api private + * @method _isFixed + * @param {Object} element + * @returns Boolean + */ + function _isFixed (element) { + var p = element.parentNode; + + if (p.nodeName === 'HTML') { + return false; + } + + if (_getPropValue(element, 'position') == 'fixed') { + return true; + } + + return _isFixed(p); + }; /** * Provides a cross-browser way to get the screen dimensions @@ -1336,6 +1363,12 @@ }(hint, item, i)); hint.className = 'introjs-hint'; + + // hint's position should be fixed if the target element's position is fixed + if (_isFixed(item.element)) { + hint.className += ' introjs-fixedhint'; + } + var hintDot = document.createElement('div'); hintDot.className = 'introjs-hint-dot'; var hintPulse = document.createElement('div'); diff --git a/introjs.css b/introjs.css index 2d9c293a5..339e0099c 100644 --- a/introjs.css +++ b/introjs.css @@ -345,6 +345,10 @@ tr.introjs-showElement > th { top: 50%; } +.introjs-fixedTooltip { + position: fixed; +} + .introjs-hint { position: absolute; background: transparent; @@ -353,7 +357,11 @@ tr.introjs-showElement > th { } .introjs-hidehint { - display: none; + display: none; +} + +.introjs-fixedhint { + position: fixed; } .introjs-hint:hover > .introjs-hint-pulse {