jQuery实现广告弹窗
首先设置一个固定的窗口位于右下角,效果如下:

代码:
jQuery实现广告弹窗.html
之后将该窗口初始设为隐藏,通过代码实现3秒自动显示,5秒自动隐藏,其效果如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery实现广告弹窗</title>
<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
<style type="text/css" > #ad{
width: 300px;
height: 300px;
background-color: antiquewhite;
position: fixed;
bottom: 0;
right: 0;
display: none;
}
</style>
<script type="text/javascript"> setTimeout(function(){
$("#ad").show(); },3000);//3秒之后就显示 setTimeout(function(){
$("#ad").hide(); },5000);//5秒之后就隐藏 </script>
</head>
<body>
<div id="ad">
<button>关闭</button> </div> </body>
</html>
实现3秒自动显示 5秒自动隐藏.html
最后通过代码实现点击事件,最终效果如下:

实现通过代码实现点击事件核心代码:
jQuery:
$(function(){
$("#closeBtn").click(function(){
$("#ad").hide();
});
});
html:
<button id="closeBtn">关闭</button>
最终所有的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery实现广告弹窗</title>
<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
<style type="text/css" > #ad{
width: 300px;
height: 300px;
background-color: antiquewhite;
position: fixed;
bottom: 0;
right: 0;
display: none;
}
</style>
<script type="text/javascript"> setTimeout(function(){
$("#ad").show(); },3000);//3秒之后就显示 setTimeout(function(){
$("#ad").hide(); },5000);//5秒之后就隐藏
$(function(){
$("#closeBtn").click(function(){
$("#ad").hide();
});
}); </script>
</head>
<body>
<div id="ad">
<button id="closeBtn">关闭</button> </div> </body>
</html>
jQuery实现广告弹窗.html
通过另一种方式执行点击事件来进行窗口的显示与隐藏:

另一种方式执行点击事件来进行窗口的显示与隐藏的核心代码:
setTimeout(function(){
$("#ad").toggle()
},1000);
$(function(){
$("#closeBtn").click(function(){
$("#ad").toggle();
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery实现广告弹窗</title>
<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
<style type="text/css" > #ad{
width: 300px;
height: 300px;
background-color: antiquewhite;
position: fixed;
bottom: 0;
right: 0;
display: none;
}
</style>
<script type="text/javascript"> // setTimeout(function(){
// $("#ad").show();
//
// },3000);//3秒之后就显示
//
// setTimeout(function(){
// $("#ad").hide();
//
// },5000);//5秒之后就隐藏
// $(function(){
// $("#closeBtn").click(function(){
// $("#ad").hide();
// });
// }); setTimeout(function(){
$("#ad").toggle()
},1000);
$(function(){
$("#closeBtn").click(function(){
$("#ad").toggle();
});
}); </script>
</head>
<body>
<div id="ad">
<button id="closeBtn">关闭</button> </div> </body>
</html>
通过toggle实现弹窗.html
当然也可以实现窗口进行动画的显示:
有这样的几个参数:slow fast 毫秒数(速度)
show() //相当于 display:block
第一个参数slow fast 毫秒数(速度)
第二个参数是回调函数
hide()
第一个参数是速度
第二个参数是回调函数
Toggle
如果是显示的就隐藏
如果是隐藏的就显示
参数slow的效果:

参数fast比参数slow快,效果如下:

参数 毫秒数(速度)自定义 例如:3秒,效果如下:

jQuery实现广告弹窗的更多相关文章
- jquery.cookie广告弹窗点击关闭后一天弹一次
jquery.cookie广告弹窗点击关闭后一天弹一次 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...
- 原生JS实现各种经典网页特效——Banner图滚动、选项卡切换、广告弹窗等
在制作网页过程中,我们可能会遇到各种常用的经典网页特效,比如Banner图片滚动.选项卡循环播放.右下角广告弹窗.评论提交展示.选项动态增删.剪刀石头布小游戏等等等...是不是感觉都见到过这些场景.那 ...
- JQ广告弹窗&随机抽奖————JQ
1.JQ广告弹窗 <div id="flo"> <img src="image.jpeg"> </div> <scri ...
- JQuery实现广告效果(滚动切换)
JQuery实现广告效果(滚动切换) Html+css 效果如上图 代码: <!DOCTYPE html> <html> <head lang="en&qu ...
- js广告弹窗
生活中我们经常遇到一些烦人的广告页面,比方说弹窗,悬浮等等各种广告.有的同事甚至都下一个屏蔽广告插件到浏览器上.这样就防止了广告的干扰. 但是我们学前端的必须是要知道广告弹窗这个做的过程,甚至是它的原 ...
- jQuery手风琴广告展示插件
效果说明:当鼠标移动到已折叠广告的标题后,折叠当前已展开的广告,并同步展开相应的折叠广告.这种Accordion效果,看似简单,但因为存在动画同步的问题,不能简单地用两个animate()来实现.必须 ...
- jQuery的dialog弹窗实现
jQuery实现dialog弹窗: html代码如下: <input type="button" onclick="performances();" va ...
- JQuery漂浮广告代码
<!doctype html><html><head><meta charset="utf-8"><title>jque ...
- 原生Js_实现广告弹窗
广告样式当页面加载后5s刷新在右下角 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
随机推荐
- [LeetCode] questions conclusion_ Binary Search
Binary Search T(n) = T(n/2) + O(1) => T(n) = O(lg n) proof: 如果能用iterable , 就用while loop, 可以防 ...
- 关于ASP.NET预编译(转自dudu)
为什么要用预编译? 博客园博客程序中.aspx和.ascx文件总共加起来有3000多个(博客模板中有大量的.ascx文件).如果使用动态编译,每次只要更新bin文件夹中的任何一个dll文件,动态编译至 ...
- apache mod_python 安装
环境:Linux 2.6.32-431.23.3.el6.i686 1.安装python .tgz ./configure --prefix=/usr/local/services/Python- ...
- centos7挂载新加4T硬盘到/home目录
以下操作均在root环境下运行. 1.查看硬盘 # fdisk -l 发现硬盘为/dev/sdb 大小4T 2.如果此硬盘以前有过分区,则先对磁盘格式化: # mkfs -t ext4 /dev/sd ...
- unity3d-游戏实战突出重围,第三天 绘制数字
实现效果: 准备资源 using UnityEngine; using System.Collections; public class hznum : MonoBehaviour { //存储图片资 ...
- Oracle 11g快速收集全库统计信息
环境:Oracle 11.2.0.4 采用并行的方式,快速收集全库统计信息,多用于跨版本升级之后,对全库的统计信息重新进行快速收集: --开启计时 set timing on --设置并行收集 exe ...
- shell编程:if语句
条件判断式的两边的空格不能生
- 14.ajax基础知识、用ajax做登录页面、用ajax验证用户名是否可用、ajax动态调用数据库
1.ajax的基础知识 ajax是结合了jquery.php等几种技术延伸出来的综合运用的技术,不是新的内容.ajax也是写在<script>标签里面的. 如果使用ajax一定是要有1个处 ...
- gitlab4.0->5.0->6.0->7.14->8.0->8.2升级
参考官方文档: https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/update 本地服务器为4.0.1版本 1)4.0.1->4. ...
- D Cloud of Hashtags Codeforces Round #401 (Div. 2)
Cloud of Hashtags [题目链接]Cloud of Hashtags &题意: 给你一个n,之后给出n个串,这些串的总长度不超过5e5,你要删除最少的单词(并且只能是后缀),使得 ...