Javascript 将简单模式弹出窗口定位在触发链接附近

Javascript 将简单模式弹出窗口定位在触发链接附近,javascript,jquery,html,Javascript,Jquery,Html,我正在使用一个插件在我的网页上创建一个小狗 <script src="/scripts/jquery.simplemodal.js"></script> <div> <div class="txt-panel" id="124853" > <div class="container"> <p>some text,...<a href="#" class="poper"> read mor

我正在使用一个插件在我的网页上创建一个小狗

<script src="/scripts/jquery.simplemodal.js"></script>
<div>
  <div class="txt-panel" id="124853" >

    <div class="container">
      <p>some text,...<a href="#" class="poper"> read more</a></p>
      <p class="popup" style="display:none" id="P1">More text, this will be a popup</p>
    </div>
  </div>
  <div class="txt-panel" id="5464641" >

    <div class="container">
      <p>some text2,...<a href="#" class="poper"> read more</a></p>
      <p class="popup" style="display:none" id="P2">More text, this will be a popup2</p>
    </div>
  </div>
</div>
这很有效。但唯一的问题是弹出窗口出现在页面的中心。但我希望弹出窗口正好位于我的锚标记上方(class=“popup”)。是否可以使用简单的模式弹出窗口。或者有没有其他更好的方法来实现我想要实现的目标?像其他插件一样


注意:您可以设置位置选项

    $(function(){
      var anchorPosition = $(".popup").position();
      $(".poper").click(function(e){
        e.preventDefault();
        $(this).parents('.container').find(".popup").modal({
          overlayClose:true,
          escClose:true,
          maxWidth:500,
          overlayClose: true,
          opacity:50,
          position:[anchorPosition.top,anchorPosition.left],
          containerCss:{background:"#f5d495"}
       });

      });
    });

您的小提琴无法工作,但我认为您也可以使用jQuery的
.appendTo()并将模式粘贴到所需的相对容器,以便更好地控制位置。这应该在模式弹出之前发生。

控制台或位置中的任何特定错误仍然是页面的中心,如果没有小提琴,则很难调试,但是你能检查一下anchorPosition.top和anchorPosition.left的值吗?我不明白,你能解释一下吗。如何检查这些值?在代码中添加console.log(anchorPosition.top+“”+anchorPosition.left)并查看锚的值,如果使用firebug控制台中的FF see,请在浏览器控制台中检查。我不完全了解您。你能添加一个代码示例吗?
    $(function(){
      var anchorPosition = $(".popup").position();
      $(".poper").click(function(e){
        e.preventDefault();
        $(this).parents('.container').find(".popup").modal({
          overlayClose:true,
          escClose:true,
          maxWidth:500,
          overlayClose: true,
          opacity:50,
          position:[anchorPosition.top,anchorPosition.left],
          containerCss:{background:"#f5d495"}
       });

      });
    });