Skip to content

Commit dd725b0

Browse files
author
Takenaka Simon
committed
center hints and add all position combinations
1 parent 238195a commit dd725b0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

docs/docs/hints/attributes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ permalink: /hints/attributes/
88
You can use these HTML attributes to manage or alter hint elements.
99

1010
- `data-hint`: The tooltip text of hint
11-
- `data-hintPosition`: Optionally define the position of hint. Options: `top-middle`, `top-left`, `top-right`, `bottom-left`, `bottom-right`, `bottom-middle`. Default: `top-middle`
11+
- `data-hintPosition`: Optionally define the position of hint. Options: `top-middle`, `top-left`, `top-right`, `bottom-left`, `bottom-right`, `bottom-middle`, `middle-left`, `middle-right`, `middle-middle`. Default: `top-middle`

intro.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,8 @@
15941594
function _alignHintPosition(position, hint, element) {
15951595
// get/calculate offset of target element
15961596
var offset = _getOffset.call(this, element);
1597+
var iconWidth = 20;
1598+
var iconHeight = 20;
15971599

15981600
// align the hint element
15991601
switch (position) {
@@ -1603,23 +1605,35 @@
16031605
hint.style.top = offset.top + 'px';
16041606
break;
16051607
case 'top-right':
1606-
hint.style.left = (offset.left + offset.width) + 'px';
1608+
hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
16071609
hint.style.top = offset.top + 'px';
16081610
break;
16091611
case 'bottom-left':
16101612
hint.style.left = offset.left + 'px';
1611-
hint.style.top = (offset.top + offset.height) + 'px';
1613+
hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
16121614
break;
16131615
case 'bottom-right':
1614-
hint.style.left = (offset.left + offset.width) + 'px';
1615-
hint.style.top = (offset.top + offset.height) + 'px';
1616+
hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
1617+
hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
1618+
break;
1619+
case 'middle-left':
1620+
hint.style.left = offset.left + 'px';
1621+
hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
1622+
break;
1623+
case 'middle-right':
1624+
hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
1625+
hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
1626+
break;
1627+
case 'middle-middle':
1628+
hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
1629+
hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
16161630
break;
16171631
case 'bottom-middle':
1618-
hint.style.left = (offset.left + (offset.width / 2)) + 'px';
1619-
hint.style.top = (offset.top + offset.height) + 'px';
1632+
hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
1633+
hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
16201634
break;
16211635
case 'top-middle':
1622-
hint.style.left = (offset.left + (offset.width / 2)) + 'px';
1636+
hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
16231637
hint.style.top = offset.top + 'px';
16241638
break;
16251639
}

0 commit comments

Comments
 (0)