提交 98e81f62 编写于 作者: K Kamran Ahmed

Add left bottom popover positioning

上级 7c716ffe
......@@ -8,21 +8,21 @@ document.addEventListener('DOMContentLoaded', function () {
title: 'Before we start',
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
nextBtnText: 'Okay, Start!',
position: 'left-center'
position: 'left-bottom'
},
}, {
element: '#logo_img',
popover: {
title: 'Focus Anything',
description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
position: 'left-center',
position: 'left-bottom',
},
}, {
element: '#name_driver',
popover: {
title: 'Why Driver?',
description: 'Because it lets you drive the user across the page',
position: 'left-center'
position: 'left-bottom'
}
}, {
element: '#driver-demo-head',
......
......@@ -132,6 +132,9 @@ export default class Popover extends Element {
case 'left-center':
this.positionOnLeftCenter(position);
break;
case 'left-bottom':
this.positionOnLeftBottom(position);
break;
case 'right':
this.positionOnRight(position);
break;
......@@ -203,6 +206,25 @@ export default class Popover extends Element {
this.tipNode.classList.add('right');
}
/**
* Shows the popover on the left of the given position
* @param {Position} elementPosition
* @private
*/
positionOnLeftBottom(elementPosition) {
const popoverDimensions = this.getSize();
const popoverWidth = popoverDimensions.width;
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
this.node.style.top = `${(elementPosition.bottom + this.options.padding) - popoverDimensions.height}px`;
this.node.style.bottom = '';
this.node.style.right = '';
this.tipNode.classList.add('right', 'position-bottom');
}
/**
* Shows the popover on the left center of the given position
* @param {Position} elementPosition
......@@ -303,13 +325,10 @@ export default class Popover extends Element {
* @private
*/
positionOnBottomRight(elementPosition) {
// const popoverWidth = this.getSize().width / 2;
// const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
this.node.style.right = `${elementPosition.left - this.options.padding}px`;
// this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
this.node.style.left = '';
this.node.style.bottom = '';
......
......@@ -62,6 +62,7 @@ div#driver-popover-item {
}
&.position-bottom {
top: auto;
bottom: 20px;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册