这次给大家带来实现弹窗功能的俩种方法,实现弹窗功能的的注意事项有哪些,下面就是实战案例,一起来看一下。
这里利用jquery实现两种弹窗效果:
1. 淡入弹窗效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery弹窗</title>
<style>
*{padding: 0;margin: 0;}
.box{width: 100%;height: 100%;}
.main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;}
.mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;}
.kkk{width: 100%;height: 1200px;background-color: red;}
.close{color: red;cursor: pointer;}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
$(".btn").click(function(){
$(".main").fadeIn();
});
$(".close").click(function(){
$(".main").fadeOut();
});
});
</script>
</head>
<body>
<p class="main">
<p class="mainbox">
<p class="close">点击关闭</p>
</p>
</p>
<p class="box">
<p class="kkk">
<input class="btn" type="button" value="点击淡入弹窗" />
</p>
</p>
</body>
</html>2. 滑动弹窗效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> jQuery弹窗</title>
<style>
*{padding: 0;margin: 0;}
.box{width: 100%;height: 100%;}
.main{width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);display: none;position: fixed;z-index: 1;}
.mainbox{width: 800px;height: 100%;margin: 0 auto;background-color: rgba(255,255,255,0.8);padding: 20px;display: none;}
.kkk{width: 100%;height: 1200px;background-color: red;}
.close{color: red;cursor: pointer;}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
$(".btn").click(function(){
$(".main").fadeIn();
$(".mainbox").delay(500).slideDown();
});
$(".close").click(function(){
$(".main").fadeOut();
});
});
</script>
</head>
<body>
<p class="main">
<p class="mainbox">
<p class="close">点击关闭</p>
</p>
</p>
<p class="box">
<p class="kkk">
<input class="btn" type="button" value="点击淡入弹窗" />
</p>
</p>
</body>
</html>相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是实现弹窗功能的俩种方法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号