【教程】随或不随窗口滚动条移动而移动的浮动广告

1.随窗口滚动条移动而移动,如图所示:

image.png

html代码

<div id="ad1">悬浮广告<span><a href="#" οnclick="closead(1);">关闭</a></span></div>

css代码

#ad1 {
    width: 60px;
    height: 120px;
    border: 1px solid #000000;
    position: absolute;
    left: 100px;
    top: 100px;
    line-height: 120px;
}
#ad1 span {
    float:right;
    line-height: 18px;
}
#ad1 span a {
    color: #000000;
    text-decoration: none;
}

javascript代码

function closead(n) {
    document.getElementById("ad"+n).style.display="none";
}

2.不随窗口滚动条移动而移动(固定位置)

html代码

<div id="ad2">悬浮广告<span><a href="#" οnclick="closead(2);">关闭</a></span></div>

css代码

#ad2 {
    float: right;
    width: 60px;
    height: 120px;
    border: 1px solid #000000;
    position: fixed;
    right: 100px;
    top: 100px;
    line-height: 120px;
}
#ad2 span {
    float:right;
    line-height: 18px;
}
#ad2 span a {
    color: #000000;
    text-decoration: none;
}

javascript同上

3.右下角提醒广告,如图所示:

image.png

html代码

<div id="ad3">提醒广告<span><a href="#" οnclick="goad3();" id="ad3a">最小化</a>&nbsp;<a href="#" οnclick="goad3(3);">关闭</a></span></div>

css代码

#ad3 {
    float: right;
    width: 360px;
    height: 220px;
    border: 1px solid #000000;
    position: fixed;
    right: 0px;
    bottom: 0px;
    line-height: 120px;
}
#ad3 span {
    float:right;
    line-height: 18px;
}
#ad3 span a {
    color: #000000;
    text-decoration: none;
}

javascript代码

var m=220;
var si;
var b=true;
function goad3(){
    si=setInterval("changead3()",10);
}
function changead3() {   
    if(b){     
        m--;
        document.getElementById("ad3").style.height=m+"px";
        if(m==34){
            document.getElementById("ad3a").innerHTML="最大化";
            clearInterval(si);
            b=false;                
        }     
    }  
    else{
        m++;
        document.getElementById("ad3").style.height=m+"px";
        if(m==220){
            document.getElementById("ad3a").innerHTML="最小化";
            clearInterval(si);
            b=true;
        }   
    }  
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hifhf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值