網站首頁 編程語言 正文
JQuery實現動態漂浮廣告&全局窗口,供大家參考,具體內容如下
以下是效果圖及實現代碼:
代碼:
<!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>鼠標懸停!</p>?? ? ?? ?<p>點擊關閉!</p>?? ? </div> <script type="text/javascript"> ?? ??? ?var isinter; ?? ??? ?var millisec = 30;//定時器間隔執行時間/毫秒 ?? ??? ?var xfloat = 0; //漂浮層x坐標 ?? ??? ?var yfloat = 0; //漂浮層y坐標 ?? ??? ?var yistop = false; ?? ??? ?var xisleft = true; ?? ??? ?function floatanimation(){ ?? ??? ?var?? ?visiblewidth = $(window).width();//可視區域寬度 ?? ??? ?var?? ?visibleheight = $(window).height();//可視區域高度 ? ?? ??? ?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
相關推薦
- 2023-03-27 react+antd?select下拉框實現模糊搜索匹配的示例代碼_React
- 2022-04-28 shell命令之mv的具體使用_linux shell
- 2022-06-30 基于Python使用永中文檔轉換服務的方式_python
- 2022-04-15 基于MFC實現自定義復選框效果_C 語言
- 2023-01-08 Android智能指針輕量級Light?Pointer初識_Android
- 2022-08-16 python+pytest接口自動化參數關聯_python
- 2022-07-10 css選擇器優先級問題
- 2022-09-24 C#中ref關鍵字的用法_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支