網(wǎng)站首頁 編程語言 正文
JQuery實現(xiàn)動態(tài)漂浮廣告&全局窗口,供大家參考,具體內(nèi)容如下
以下是效果圖及實現(xiàn)代碼:
代碼:
<!DOCTYPE html> <html lang="en"> <head> ?? ?<meta charset="UTF-8"> ?? ?<title>漂浮廣告欄</title> ?? ?<script type="text/javascript" src="js/jquery-3.2.1.js"></script> ?? ?<style type="text/css"> ?? ??? ?body{ ?? ??? ??? ?height: 100%; ?? ??? ??? ?width: 100%; ?? ??? ??? ?margin: 0; ?? ??? ??? ?padding: 0; ?? ??? ??? ?text-align: center; ?? ??? ?} ?? ??? ?#floatdiv{ ?? ??? ??? ?width: 200px; ?? ??? ??? ?height: 200px; ?? ??? ??? ?position: absolute; ?? ??? ??? ?top: 0; ?? ??? ??? ?left: 0; ?? ??? ??? ?background-color: #fbb; ?? ??? ??? ?z-index: 999; ?? ??? ??? ?border: 1px solid #ccc; ?? ??? ??? ?border-radius: 10px 10px ; ?? ??? ?} ?? ??? ?span{ ?? ??? ??? ?position: absolute; ?? ??? ??? ?top: 0; ?? ??? ??? ?right: 0; ?? ??? ??? ?color: darksalmon; ?? ??? ??? ?background-color: rgba(0, 0, 0, 0.5); ?? ??? ??? ?padding: 0 5px; ?? ??? ??? ?cursor: pointer; ?? ??? ??? ?border-radius: 20% 20%; ?? ??? ?} ?? ?</style> ?? ? </head> <body> <div id="floatdiv"> ?? ?<span id="Clickclose" >X</span> ?? ?<p>鼠標(biāo)懸停!</p>?? ? ?? ?<p>點擊關(guān)閉!</p>?? ? </div> <script type="text/javascript"> ?? ??? ?var isinter; ?? ??? ?var millisec = 30;//定時器間隔執(zhí)行時間/毫秒 ?? ??? ?var xfloat = 0; //漂浮層x坐標(biāo) ?? ??? ?var yfloat = 0; //漂浮層y坐標(biāo) ?? ??? ?var yistop = false; ?? ??? ?var xisleft = true; ?? ??? ?function floatanimation(){ ?? ??? ?var?? ?visiblewidth = $(window).width();//可視區(qū)域?qū)挾? ?? ??? ?var?? ?visibleheight = $(window).height();//可視區(qū)域高度 ? ?? ??? ?var?? ?divwidth = $('#floatdiv').width();//div漂浮層寬度 ?? ??? ?var divheight = $('#floatdiv').height();//div漂浮層高度 ? ?? ??? ?var hstop = jQuery(window).scrollTop();//滾動條距離頂部的高度 ?? ??? ?var wsleft = jQuery(window).scrollLeft();//滾動條距離最左邊的距離 ? ?? ??? ?var offwidth = (visiblewidth-divwidth);//div偏移的寬度 ?? ??? ?var offheight = (visibleheight-divheight);//div偏移的高度 ? ?? ??? ??? ?if (!yistop) { ?? ??? ??? ??? ?yfloat++; ?? ??? ??? ??? ?if (yfloat >= offheight) { ?? ??? ??? ??? ??? ?yistop = true; ?? ??? ??? ??? ?} ?? ??? ??? ?} else { ?? ??? ??? ??? ?yfloat--; ?? ??? ??? ??? ?if (yfloat <= 0) { ?? ??? ??? ??? ??? ?yistop = false; ?? ??? ??? ??? ?} ?? ??? ??? ?} ? ?? ??? ??? ?if (xisleft) { ?? ??? ??? ??? ?xfloat++; ?? ??? ??? ??? ?if (xfloat >= offwidth) { ?? ??? ??? ??? ??? ?xisleft = false; ?? ??? ??? ??? ?} ?? ??? ??? ?} else { ?? ??? ??? ??? ?xfloat--; ?? ??? ??? ??? ?if (xfloat <= 0) { ?? ??? ??? ??? ??? ?xisleft = true; ?? ??? ??? ??? ?} ?? ??? ??? ?} ? ? ? ? ?/* 如果使用固定定位,請把加上滾動條的距離去掉即可 */ ?? ??? ??? ?$('#floatdiv').css({'top':yfloat+hstop,'left':xfloat+wsleft}); ?? ??? ?} ? ?? ??? ?$(function () { ?? ??? ??? ?isinter = setInterval("floatanimation()",millisec); ?? ??? ??? ?$('#floatdiv').mouseover(function () { ?? ??? ??? ??? ?clearInterval(isinter); ?? ??? ??? ?}).mouseout(function () { ?? ??? ??? ??? ?isinter = setInterval("floatanimation()",millisec); ?? ??? ??? ?}); ?? ??? ??? ?$('#Clickclose').click(function () { ?? ??? ??? ??? ?$(this).parents("#floatdiv").slideUp(500,function(){ ?? ??? ??? ??? ??? ?clearInterval(isinter); ?? ??? ??? ??? ??? ?$(this).remove(); ?? ??? ??? ??? ?}); ?? ??? ??? ?}); ?? ??? ?}); ?? ?</script> </body> </html>
原文鏈接:https://blog.csdn.net/lyh_0301/article/details/99410643
相關(guān)推薦
- 2022-05-06 一起來看看C++STL容器之string類_C 語言
- 2022-08-13 beginInvoke加回調(diào)函數(shù)lamad
- 2022-04-09 SpringBoot自定義Validated枚舉校驗器
- 2023-11-18 數(shù)據(jù)處理使用Python提取String、字符串中的數(shù)字
- 2023-03-15 手把手教你用Python中的Linting提高代碼質(zhì)量_python
- 2022-05-08 輕量級ORM框架Dapper應(yīng)用支持操作函數(shù)和事物_實用技巧
- 2022-10-05 Ubuntu?Server?20.04?LTS?環(huán)境下搭建vim?編輯器Python?IDE的詳細(xì)步
- 2022-04-22 使用elementui,upload組件,既要上傳文件,又要提交表單
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支