AlertBox 弹出层(信息提示框)效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用JavaScript和CSS来创建一个自定义的Alert弹出框,并使用setTimeout函数来使其在一段时间后自动消失。 首先,您可以使用以下HTML代码创建一个弹出框的框架: ```html <div id="myAlert" class="alert"> <span class="closebtn" onclick="closeAlert()">×</span> <strong>Alert:</strong> This is a custom alert box. </div> ``` 然后,您可以使用以下CSS样式来自定义弹出框的样式: ```css .alert { padding: 20px; background-color: #f44336; color: white; border-radius: 5px; position: fixed; bottom: 0; right: 0; margin-right: 20px; margin-bottom: 20px; z-index: 9999; animation: slidein 0.5s, fadeout 0.5s 2.5s; } .closebtn { margin-left: 15px; color: white; font-weight: bold; float: right; font-size: 22px; line-height: 20px; cursor: pointer; transition: 0.3s; } .closebtn:hover { color: black; } @keyframes slidein { from {bottom: -100px; opacity: 0;} to {bottom: 0; opacity: 1;} } @keyframes fadeout { from {opacity: 1;} to {opacity: 0;} } ``` 最后,您可以使用以下JavaScript代码来显示和关闭弹出框,并设置setTimeout函数来在一段时间后自动关闭弹出框: ```javascript function showAlert() { var alertBox = document.getElementById("myAlert"); alertBox.style.display = "block"; setTimeout(function(){ alertBox.style.display = "none"; }, 3000); } function closeAlert() { var alertBox = document.getElementById("myAlert"); alertBox.style.display = "none"; } ``` 通过调用showAlert函数,您可以显示一个自定义的Alert弹出框,并在3秒后自动关闭。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值