HTML公告浮窗,可自定义按钮功能

HTML公告浮窗

实现效果

![Alt](https://img-home.csdnimg.cn/images/20220524100510.png在这里插入图片描述

实现代码

css

.web_notice {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99999;
}

.web_notice_content {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 550px;
    background: rgb(36, 46, 59);
    transform: translate(-50%, -50%);
    border-radius: 40px;
    padding: 50px 40px;
    color: rgb(255, 255, 255);
    word-wrap: break-word;
}

.web_notice_title {
    color: rgb(173, 134, 252);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.web_notice_text {
    margin-bottom: 20px;
}

.web_notice_buttons {
    display: flex;
    justify-content: space-between;
}

.web_notice_button {
    display: block;
    background: rgb(173, 134, 252);
    color: #FFF;
    text-align: center;
    font-weight: bold;
    font-size: 19px;
    line-height: 49px;
    border-radius: 5px;
    width: 40%;
}

.support_button {
    float: left;
}

.acknowledge_button {
    float: right;
}


javascript

function closeWebNotice() {
    document.querySelector('.web_notice').remove();
}

html

<div class="web_notice">
    <div class="web_notice_content">
        <h2 class="web_notice_title">本站已开通爱发电赞助平台</h2>
        <p class="web_notice_text">
            为维护网站的正常运作,本站设立独立服务器,并开通了新的运营商宽带,产生了不小的费用。作者为个人开发者,没有团队,费用均由一人承担。现在开通高级订阅通道,具体信息:<br>
            1. 订阅费用:5元/月。<br>
            2. 订阅期间:<br>
            &nbsp;&nbsp;&nbsp;&nbsp;a. 可享受最新的内测功能;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;b. 解锁高级功能使用权;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;c. 让作者买杯奶茶回回血。
        </p>
        <div class="web_notice_buttons">
            <a href="https://afdian.net/order/create?plan_id=" class="web_notice_button support_button">
                支持一下
            </a>
            <a class="web_notice_button acknowledge_button" onclick="closeWebNotice()">
                我知道了
            </a>
        </div>
    </div>
</div>


整合形式

可直接内嵌在html中

<div class="web_notice" style="position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:99999;">
  <div style="position:fixed;top:50%;left:50%;width:550px;background:rgb(36,46,59);transform:translate(-50%,-50%);border-radius:40px;padding:50px 40px;">
    <div style="color:#FFF;word-wrap:break-word;"><h2 style="color:#AD86FC;display:flex;flex-direction:column;align-items:center;">本站已开通爱发电赞助平台</h2>为维护网站的正常运作,本站设立独立服务器,并开通了新的运营商宽带,产生了不小的费用。作者为个人开发者,没有团队,费用均由一人承担。现在开通高级订阅通道,具体信息:<br>1,订阅费用:5元/月。<br>2,订阅期间:<br>&nbsp;&nbsp;&nbsp;&nbsp;a,可享受最新的内测功能;<br>&nbsp;&nbsp;&nbsp;&nbsp;b,解锁高级功能使用权;<br>&nbsp;&nbsp;&nbsp;&nbsp;c,让作者买杯奶茶回回血。</div>
    <div>
      <a href="https://afdian.net/order/create?plan_id=" style="display:block;background:#AD86FC;color:#FFF;text-align:center;font-weight:bold;font-size:19px;line-height:49px;margin-top:11px;border-radius:5px;width:40%;float:left;">支持一下</a>
      <a style="user-select:none;display:block;background:#AD86FC;color:#FFF;text-align:center;font-weight:bold;font-size:19px;line-height:49px;margin-top:11px;border-radius:5px;width:40%;float:right;" onclick="javascript:document.querySelector('.web_notice').remove()">我知道了</a>
    </div>
  </div>
</div>

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值