popup - 如何为点击弹出窗口添加 Jquery 或 javascript 函数?
问题描述
解决方案
您可以最初使用 CSS 隐藏弹出内容,然后使用 jQuery fadeIn()
/fadeOut()
分别显示/隐藏弹出内容。
示例 HTML:
<a href="#" class="click-to-open">click to open popup</a>
<div class="popup-content"> <!-- use display:none to hide initially -->
<a href="#" class="popup-close">x</a>
<h1>Lorem Ipsum</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
</div>
jQuery点击功能:
jQuery(document).ready(function($){
$('.click-to-open').on('click', function(e){
e.preventDefault();
$('.popup-content').fadeIn();
});
$('.popup-close').on('click', function(e){
e.preventDefault();
$('.popup-content').fadeOut();
}
});
检查以下小提琴的工作示例:https ://jsfiddle.net/tvaunsg3/1/
您可以在弹出窗口处于活动状态时使用toggleClass()
on创建一些叠加层。body
或者,如果您需要更高级的功能(回调等),您也可以使用jQuery Modal或Magnific Popup 。
推荐阅读
- python - 有什么方法可以修复python中导入时的语法错误?
- mysql - Spring Boot + MySQL + Docker Compose - Cannot make Spring Boot connect to MySQL
- python - AttributeError: 'Turtle' 对象在第 14 行没有属性 'shapesize'
- maven - 如何解决这个问题:无法执行目标 org.codehaus.mojo:exec-maven-plugin:1.4.0:exec(安装程序)
- excel - 使用工作表中的输入值来引用不同的工作表 vba
- android - 如何更正 NativeScript 应用程序中“下载”文件夹中的读取文件?
- reactjs - 将函数传递给组件以用作 onClick 反应
- java - 单元测试时如何设置全局环境变量
- python - flask_login 会话在注销后生效
- doxygen - 为什么 Doxygen 不能解析我调用图中的大多数方法?