如何使用popper.js从referenceObject偏移dataObject?

时间:2018-06-15 07:51:33

标签: popper.js

如何将boatanchor偏移几个像素?

您可以找到我在此处尝试设置偏移失败的代码笔

https://codepen.io/anon/pen/wXraLK?editors=1111

HTML

<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>

<div class="anchor">Anchor</div>
<div class="boat">Boat</div>

CSS

.boat {
  display: inline-block;
  background-color: yellow;
}
.anchor {
  display: inline-block;
  background-color: gray;
}

的JavaScript

var anchor = document.getElementsByClassName("anchor")[0];
var boat = document.getElementsByClassName("boat")[0];

var offsetTopModifier = function (data) {
  data.offsets.popper.top += 50;
  return data;
}

var popper = new Popper(
  anchor,
  boat,
  {
    placement: 'bottom-end',
    modifiers: [offsetTopModifier]
  }
);

这是激发我尝试的源泉:

https://github.com/FezVrasta/popper.js/issues/107

1 个答案:

答案 0 :(得分:0)

一项工作就是在船上设置利润。