Skip to content

Commit 724dc5d

Browse files
committed
Fix bad width, height calculation + code cleanup/add comments
1 parent f193c95 commit 724dc5d

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

intro.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,33 @@
211211

212212
if(oldHelperLayer != null) {
213213
var oldHelperNumberLayer = oldHelperLayer.querySelector(".introjs-helperNumberLayer"),
214-
oldtooltipLayer = oldHelperLayer.querySelector(".introjs-tooltiptext"),
215-
oldArrowLayer = oldHelperLayer.querySelector(".introjs-arrow"),
216-
oldtooltipContainer = oldHelperLayer.querySelector(".introjs-tooltip")
214+
oldtooltipLayer = oldHelperLayer.querySelector(".introjs-tooltiptext"),
215+
oldArrowLayer = oldHelperLayer.querySelector(".introjs-arrow"),
216+
oldtooltipContainer = oldHelperLayer.querySelector(".introjs-tooltip")
217+
218+
//hide the tooltip
219+
oldtooltipContainer.style.opacity = 0;
217220

218221
//set new position to helper layer
219222
oldHelperLayer.setAttribute("style", "width: " + (elementPosition.width + 10) + "px; " +
220223
"height:" + (elementPosition.height + 10) + "px; " +
221224
"top:" + (elementPosition.top - 5) + "px;" +
222225
"left: " + (elementPosition.left - 5) + "px;");
223-
//set current step to the label
224-
oldHelperNumberLayer.innerHTML = targetElement.getAttribute("data-step");
225-
//set current tooltip text
226-
oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
226+
//remove old classes
227227
var oldShowElement = document.querySelector(".introjs-showElement");
228228
oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim();
229-
_placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer);
229+
//we should wait until the CSS3 transition is competed (it's 0.3 sec) to prevent incorrect `height` and `width` calculation
230+
setTimeout(function() {
231+
//set current step to the label
232+
oldHelperNumberLayer.innerHTML = targetElement.getAttribute("data-step");
233+
//set current tooltip text
234+
oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
235+
//set the tooltip position
236+
_placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer);
237+
//show the tooltip
238+
oldtooltipContainer.style.opacity = 1;
239+
}, 350);
240+
230241
} else {
231242
var helperLayer = document.createElement("div"),
232243
helperNumberLayer = document.createElement("span"),

introjs.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@
103103
background-color: white;
104104
border-radius: 3px;
105105
box-shadow: 0 1px 10px rgba(0,0,0,.4);
106-
-webkit-transition: all 0.1s ease-out;
107-
-moz-transition: all 0.1s ease-out;
108-
-ms-transition: all 0.1s ease-out;
109-
-o-transition: all 0.1s ease-out;
110-
transition: all 0.1s ease-out;
106+
-webkit-transition: opacity 0.1s ease-out;
107+
-moz-transition: opacity 0.1s ease-out;
108+
-ms-transition: opacity 0.1s ease-out;
109+
-o-transition: opacity 0.1s ease-out;
110+
transition: opacity 0.1s ease-out;
111111
}
112112

113113
.introjs-tooltipbuttons {

0 commit comments

Comments
 (0)