javascript - 如何用 jQuery 创建固定对话框?

标签 javascript jquery html

给你一个众所周知的例子更容易:

如果您使用 Google 登录,则可以单击右上角的个人资料图标,然后会出现一个类似对话框。我怎样才能做类似的事情?我猜它可能是用 jQuery 制作的。我发现最重要的是你创建了一个带有切换功能的div,但这不是最好的,因为它会下推整个页面内容。

而且它似乎也不是一个简单的 JavaScript 提示...(但我没有足够的经验来判断它...)

你知道如何创建这样的东西吗?谢谢!!

最佳答案

这是一个如何使用 jQuery 执行此操作的简单示例。

$('.button').on('click', function() {
  $('.hoverelement').toggle();
});
.hoverelement {
  display: none;
  border: solid 1px;
  background-color: #fff;
  width: 200px;
  text-align: left;
  position: relative;
  top: 10px;
  z-index: 10;
}
.container {
  position: absolute;
}
.othercontent {
  position: absolute;
  top: 50px;
  z-index: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="button">Button</div>
  <div class="hoverelement">
    <h1>your content here</h1>
    <p>put some content here</p>
  </div>
</div>
<div class="othercontent">
  other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />other content
  <br />
</div>

关于javascript - 如何用 jQuery 创建固定对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30422259/

相关文章:

javascript - 使用 indexOf() 比较数组中的字符

javascript - 检查请求是否来自网络而不是手动

javascript - 在 jQuery 中,如何在用户输入时检测指定的字符串?

jquery - 可排序/可拖动布局选择器的最佳选择?

php - 限制textarea中的字符 - 转义引号和双引号在MySQL中占用2个字符

使用 BuckleScript 的 ReasonML 中的 JavaScript 构造函数行为

javascript - 在一串 javascript 代码中查找正则表达式文字

javascript - 如何在页面加载时默认隐藏 Accordion 类型中的所有 div?

javascript - 如何在javascript中输入名称和id的值?

javascript - 使用 Emailjs 时,我的收件箱没有收到表单输入信息