-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwalkme.js
37 lines (31 loc) · 1.09 KB
/
walkme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function () {
const balloonData = {
targetSelector: '#item1',
width: 100,
height: 50,
text: 'drag me',
closeTrigger: 'dragend'
};
function drawBalloon(data) {
const target = document.querySelector(data.targetSelector);
const balloon = document.createElement('div');
const targetRect = target.getClientRects()[0];
balloon.style.position = 'absolute';
balloon.style.top = `${targetRect.bottom + 5}px`;
balloon.style.left = `${(targetRect.right + targetRect.left - data.width) / 2}px`;
balloon.style.width = `${data.width}px`;
balloon.style.height = `${data.height}px`;
balloon.style.backgroundColor = 'coral';
balloon.style.borderTop = '3px solid red';
balloon.innerText = data.text;
target.parentElement.appendChild(balloon);
target.addEventListener(data.closeTrigger, function () {
balloon.remove();
});
}
window.walkme = {
play() {
drawBalloon(balloonData);
}
};
})();