页面上无法屏蔽的左右两侧的漂浮图片广告

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>页面上无法屏蔽的左右两侧的漂浮图片广告丨益诚制衣-纳豆激酶</title>
    <meta http-equiv="content-type" content="text/html;charset=gb2312">
    <!--把下面代码加到<head>与</head>之间-->
    <style type="text/css">
    .l1{
    width:100px;height:100px;background:red;float:right;
    position:fixed !important;top:200px;
    position:absolute;z-index:300;top:expression(offsetParent.scrollTop+200);left:10px;
    }
    .r1{
    width:100px;height:100px;background:red;float:right;
    position:fixed !important;top:200px;
    position:absolute;z-index:300;top:expression(offsetParent.scrollTop+200);right:10px;
    }
    </style>
    </head>
    <body>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
    <!--把下面代码加到<body>与</body>之间-->
    <div class="l1"><a href="http://www.CsrCode.cn" target="_blank"><img src="/images/20110809/piaofu.gif" width="100" height="100" border="0"></a></div>
    <div class="r1"><a href="http://www.7caidy.com" target="_blank"><img src="/images/20110809/piaofu.gif" width="100" height="100" border="0"></a></div>
    </body>
    </html>
    <br><br><hr>
    

 

转载于:https://www.cnblogs.com/youtianxia/p/4174477.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的示例,漂浮广告为一个图片,当鼠标停在图片上时,广告停止漂浮,离开时继续漂浮: HTML代码: ``` <div id="floatAd"> <img src="广告图片地址" alt="广告"> </div> ``` CSS代码: ``` #floatAd { position: fixed; bottom: 0; right: 0; } #floatAd img { width: 200px; height: 200px; cursor: pointer; } ``` JavaScript代码: ``` var floatAd = document.getElementById('floatAd'); var adImg = floatAd.getElementsByTagName('img')[0]; var dx = 2; // 漂浮距离 var dy = 2; var floatInterval = setInterval(function() { var x = parseFloat(floatAd.style.right); var y = parseFloat(floatAd.style.bottom); if (x <= 0 || x >= (window.innerWidth - adImg.width)) { dx = -dx; } if (y <= 0 || y >= (window.innerHeight - adImg.height)) { dy = -dy; } floatAd.style.right = (x + dx) + 'px'; floatAd.style.bottom = (y + dy) + 'px'; }, 10); adImg.addEventListener('mouseover', function() { clearInterval(floatInterval); }); adImg.addEventListener('mouseout', function() { floatInterval = setInterval(function() { var x = parseFloat(floatAd.style.right); var y = parseFloat(floatAd.style.bottom); if (x <= 0 || x >= (window.innerWidth - adImg.width)) { dx = -dx; } if (y <= 0 || y >= (window.innerHeight - adImg.height)) { dy = -dy; } floatAd.style.right = (x + dx) + 'px'; floatAd.style.bottom = (y + dy) + 'px'; }, 10); }); ``` 解释: - 通过`getElementById`方法获取漂浮广告节点和图片节点; - 定义漂浮距离`dx`和`dy`,并设置漂浮间隔为10毫秒; - 使用`setInterval`方法循环移动广告,当广告到达窗口边缘时改变漂浮方向; - 当鼠标停在图片上时,使用`clearInterval`方法停止漂浮; - 当鼠标离开图片时,重新开始漂浮。 注意事项: - 漂浮广告的位置使用`position: fixed`实现,需要在CSS中设置`bottom`和`right`属性; - 图片节点需要设置`cursor: pointer`属性,以便在鼠标停在图片上时改变鼠标指针形状; - 可以根据实际需求调整漂浮距离和漂浮间隔。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值