日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

JQuery實現(xiàn)動態(tài)漂浮廣告_jquery

作者:lyh_0301 ? 更新時間: 2022-06-02 編程語言

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

欄目分類
最近更新