JS实现对联广告和弹窗广告代码,可同时关闭不随屏幕滚动

JS代码如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
                body{
                    margin: 0;
                    padding: 0;
                }
                
                .web{
                    width: 1000px;
                    height: 1500px;
                    background-color: #CCCCCC;
                    border: #666666 1px solid;
                    margin: 0 auto;
                    
                }
                /*对联广告样式*/
                #ad1,#ad2{
                    position: fixed;
                    top:50px;
                    width:100px;
                    height: 200px;
                    background-image: url(ad1.jpg);
                   
                }
                #ad1{left: 0;}/*靠左*/
                #ad2{right:0 ;}/*靠右*/
                /*弹窗广告样式*/
                #ad3{
                    position: fixed;
                    bottom:0px;/*右下*/
                    right:0px;
                    height:250px ;
                    width:300px ;
                    background-image: url(ad2.jpg);
                }
                /*关闭按钮图片样式*/
                #close,#close1{
                    
                    width: 50px;
                    height:15px ;
                    object-fit: cover;
                    position: absolute;
                    bottom:0;
                    right:0;
                    background-image: url(close.png);
                    background-repeat:no-repeat;
                    background-size:cover;
                    background-position:center center;
                }
                
                #close3{
                    
                    width: 50px;
                    height:15px ;
                    object-fit: cover;
                    position: absolute;
                    top:0;
                    right:0;
                    background-image: url(close.png);
                    background-repeat:no-repeat;
                    background-size:cover;
                    background-position:center center;
                }
            </style>
    </head>
    <body>
        <div id=ad1>
            <div id="close" ></div>
        </div>
        <div class="web"></div>
        <div id=ad2>
            <div id="close1" ></div>
        </div>
        <div id="ad3" style="display:none;"><div id="close3"></div></div>
    </body>
    <script type="text/javascript">
        var close=document.querySelector("#close");
        var close1=document.querySelector("#close1");
        var close3=document.querySelector("#close3");
        var ad1=document.getElementById('ad1');
        var ad2=document.getElementById('ad2');
//        关闭左边
        close.οnclick=function(){
        ad1.style.display="none";
        ad2.style.display="none";
        
        }
//        关闭右边   
        close1.οnclick=function(){
        ad1.style.display="none";
        ad2.style.display="none";
    
        
        }
//        关闭弹窗广告        
        close3.οnclick=function(){
        var ad3=document.getElementById('ad3');
        ad3.style.display="none";
        
        
        }
//1.5s弹出弹窗广告
window.οnlοad=function(){//页面加载事件
        var ad3=setTimeout(function(){
        var ad3=document.getElementById('ad3');
        ad3.style.display="inline"
    },1500)
        }
    </script>
</html>

实现效果如下:

 自己写的代码,欢迎各位大佬指正~

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值