使用jQuery在右下角的位置

时间:2015-08-15 18:29:31

标签: javascript jquery html css

我试图将对话框放在页面的右下角,但我没有成功。

我做错了什么?

<script>
  $(function() {
    $("#dialog").dialog();

    {
      position: fixed;
      right: 0;
      bottom: 0;
    }

  });
</script>​

2 个答案:

答案 0 :(得分:2)

查看我的codepen。您可以在对话框中添加位置(请参阅docs)。这是完整的jQuery代码:

$(function() {
    $( "#dialog" ).dialog({
        position: {
            my: "left top",
            at: "right bottom"
        }
    });
});

答案 1 :(得分:0)

您可以使用jQuery.css()来应用CSS规则。

&#13;
&#13;
$(function() {
  // $('#dialog').dialog();
  $("#dialog").css({
    'position': 'fixed',
    'bottom': 0,
    'right': 0
  });
});
&#13;
div {
  width: 100px;
  height: 100px;
  background: url('//placehold.it/100x100');
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="dialog"></div>
&#13;
&#13;
&#13;

但是不应该有任何理由使用jQuery来实现这一点,因为仅使用CSS就完全有可能。

&#13;
&#13;
div {
  width: 100px;
  height: 100px;
  background: url('//placehold.it/100x100');
  position: fixed;
  bottom: 0;
  right: 0;
}
&#13;
<div id="dialog"></div>
&#13;
&#13;
&#13;