Skip to content

Commit 324c982

Browse files
committed
Fix position relative/absolute bug
1 parent a9b8869 commit 324c982

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

intro.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
//remove `introjs-showElement` class from the element
146146
var showElement = document.querySelector(".introjs-showElement");
147147
if (showElement) {
148-
showElement.className = showElement.className.replace(/introjs-showElement/,'').trim();
148+
showElement.className = showElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim();
149149
}
150150
//clean listeners
151151
targetElement.onkeydown = null;
@@ -226,13 +226,9 @@
226226
//set current tooltip text
227227
oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
228228
var oldShowElement = document.querySelector(".introjs-showElement");
229-
oldShowElement.className = oldShowElement.className.replace(/introjs-showElement/,'').trim();
230-
//change to new intro item
231-
targetElement.className += " introjs-showElement";
229+
oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim();
232230
_placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer);
233231
} else {
234-
targetElement.className += " introjs-showElement";
235-
236232
var helperLayer = document.createElement("div"),
237233
helperNumberLayer = document.createElement("span"),
238234
arrowLayer = document.createElement("div"),
@@ -284,6 +280,24 @@
284280
_placeTooltip(targetElement, tooltipLayer, arrowLayer);
285281
}
286282

283+
//add target element position style
284+
targetElement.className += " introjs-showElement";
285+
286+
//Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml
287+
var currentElementPosition = "";
288+
if (targetElement.currentStyle) { //IE
289+
currentElementPosition = targetElement.currentStyle["position"];
290+
} else if (document.defaultView && document.defaultView.getComputedStyle) { //Firefox
291+
currentElementPosition = document.defaultView.getComputedStyle(targetElement, null).getPropertyValue("position");
292+
}
293+
294+
//I don't know is this necessary or not, but I clear the position for better comparing
295+
currentElementPosition = currentElementPosition.toLowerCase();
296+
if (currentElementPosition != "absolute" && currentElementPosition != "relative") {
297+
//change to new intro item
298+
targetElement.className += " introjs-relativePosition";
299+
}
300+
287301
//scroll the page to the element position
288302
if (typeof(targetElement.scrollIntoViewIfNeeded) === "function") {
289303
//awesome method guys: https://bugzilla.mozilla.org/show_bug.cgi?id=403510

introjs.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
}
1212

1313
.introjs-showElement {
14-
position: relative;
1514
z-index: 9999999;
1615
}
1716

17+
.introjs-relativePosition {
18+
position: relative;
19+
}
20+
1821
.introjs-helperLayer {
1922
position: absolute;
2023
z-index: 9999998;

0 commit comments

Comments
 (0)