Skip to content

Commit 2a882fc

Browse files
author
Yaron Nachshon
committed
arrow
1 parent c5f3f38 commit 2a882fc

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

intro.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
return offset;
7272
}
7373

74-
function fitOffsetToScreen(offset, width, height){
74+
function fitOffsetToScreen(offset, width){
7575
var bodyBoundingClientRect = $('body').get(0).getBoundingClientRect();
7676
var delta;
7777
if((offset.left + width) > bodyBoundingClientRect.right){
@@ -86,11 +86,13 @@
8686

8787
function outerPositionElement(element, target, position){
8888
var offset = convertOuterPositionToOffset(element, target, position);
89-
offset = fitOffsetToScreen(offset, element.outerWidth(), element.outerHeight());
89+
offset = fitOffsetToScreen(offset, element.outerWidth());
9090
return element.offset(offset);
9191
}
9292

9393

94+
95+
9496
function Hint(){
9597
var tooltip;
9698
var that = this;
@@ -99,9 +101,39 @@
99101
var hintPosition;
100102
var wasRendered = false;
101103

104+
function getTooltipArrowElement(){
105+
return tooltip.find('.intro-tooltip-arrow');
106+
}
102107

108+
function difference(a, b) {
109+
return Math.abs(a - b);
110+
}
103111

112+
function createTooltip(){
113+
var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>')
114+
.addClass('intro-tooltip');
115+
tooltip.hide();
116+
$('body').append(tooltip);
117+
return tooltip;
118+
}
119+
120+
function repositionTooltipArrow(){
121+
var tooltipArrowElement = getTooltipArrowElement();
122+
tooltipArrowElement.css({'left': 0});
123+
var elementBoundingClientRect = that.element.get(0).getBoundingClientRect();
124+
var tooltipBoundingClientRect = tooltip.get(0).getBoundingClientRect();
125+
var delta = difference(elementBoundingClientRect.left, tooltipBoundingClientRect.left);
126+
127+
tooltipArrowElement.css({left: delta});
128+
129+
}
104130

131+
function createHint(){
132+
var hint = $('<div class="intro-hint"><div class="intro-circle"></div></div>');
133+
hint.hide();
134+
$('body').append(hint);
135+
return hint;
136+
}
105137

106138
this.element = null;
107139

@@ -135,29 +167,17 @@
135167

136168
that.element.show();
137169
innerPositionElement(that.element, targetElement, hintPosition, duration).then(function(){
170+
getTooltipArrowElement().attr('position', tooltipPosition);
138171
tooltip.css('opacity', 0).show();
139172
outerPositionElement(tooltip, that.element, tooltipPosition);
173+
repositionTooltipArrow();
140174
tooltip.animate({'opacity': 1});
141175
defer.resolve();
142176
});
143177
wasRendered = true;
144178
return defer.promise();
145179
};
146180

147-
function createTooltip(){
148-
var tooltip = $('<div><div class="intro-tooltip-content"></div><div class="intro-tooltip-arrow"></div></div>')
149-
.addClass('intro-tooltip');
150-
tooltip.hide();
151-
$('body').append(tooltip);
152-
return tooltip;
153-
}
154-
155-
function createHint(){
156-
var hint = $('<div class="intro-hint"><div class="intro-circle"></div></div>');
157-
hint.hide();
158-
$('body').append(hint);
159-
return hint;
160-
}
161181

162182
function init(){
163183
that.element = createHint();
@@ -225,7 +245,7 @@
225245

226246
function showStep(step){
227247
var _showStep = function(){
228-
hint = hint || new Hint();
248+
hint = hint || new Hint();
229249
backdrop = backdrop || createBackdrop();
230250

231251
hint.setTarget(step.element || $('body'));

introjs.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

introjs.scss

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// @include arrow(top, #000, 50px);
1010
// }
1111

12-
$arrow-size-border: 5px;
12+
$arrow-size-border: 10px;
1313
$arrow-size: $arrow-size-border * 2;
1414

1515
@mixin arrow($direction, $color, $size){
@@ -80,25 +80,35 @@ $arrow-size: $arrow-size-border * 2;
8080
position: absolute;
8181
}
8282

83+
.intro-tooltip-arrow {
84+
&[position=right]{
85+
@include arrow('left', red, $arrow-size-border);
86+
}
87+
&[position=left]{
88+
@include arrow('right', red, $arrow-size-border);
89+
}
90+
&[position=bottom]{
91+
@include arrow('top', red, $arrow-size-border);
92+
}
93+
&[position=top]{
94+
@include arrow('bottom', red, $arrow-size-border);
95+
top: 0;
96+
}
97+
}
98+
8399
&.right {
84100
top: 50%;
85101
transform: translateY(-50%);
86102
left: calc(100% + 12px);
87-
.intro-tooltip-arrow {
88-
@include arrow('left', red, $arrow-size-border);
89-
left: -($arrow-size / 2);
90-
top: calc(50% - #{$arrow-size / 2});
91-
}
103+
92104
}
93105

94106
&.left {
95107
top: 50%;
96108
right: calc(100% + 13px );
97109
transform: translateY(-50%);
98110
.intro-tooltip-arrow {
99-
@include arrow('right', red, $arrow-size-border);
100-
left: 100%;
101-
top: calc(50% - #{$arrow-size / 2});
111+
102112
}
103113
}
104114

@@ -107,9 +117,7 @@ $arrow-size: $arrow-size-border * 2;
107117
left: 50%;
108118
transform: translateX(-50%);
109119
.intro-tooltip-arrow {
110-
@include arrow('top', red, $arrow-size-border);
111-
left: calc(50% - #{$arrow-size / 2});
112-
top: -($arrow-size / 2);
120+
113121
}
114122
}
115123

@@ -118,9 +126,7 @@ $arrow-size: $arrow-size-border * 2;
118126
left: 50%;
119127
transform: translateX(-50%);
120128
.intro-tooltip-arrow {
121-
@include arrow('bottom', red, $arrow-size-border);
122-
left: calc(50% - #{($arrow-size / 2)});
123-
top: 100%;
129+
124130
}
125131
}
126132
}

0 commit comments

Comments
 (0)