</style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> $(function(){ $('a.alert').unbind("click").on("click",function(){ OnAlert($(this).attr('box-title'),$(this).attr('box-content'),$(this).attr('box-action')); return false; }) }); function OnAlert(title, content, button){ bt=''; forward=''; if(title && content){ if(button){ vb=JSON.parse(button); for(i=0;i<vb.length;i++){ if(vb[i]['action']=='close'){ bt+=' <a class="box-button box-close-alert">'+vb[i]['title']+'</a>'; }else{ if(vb[i]['forward']){ forward=' forward="'+vb[i]['forward']+'"'; }else{ forward=' forward="'+vb[i]['action']+'"'; } bt+=' <a class="box-button box-link no-load" href="'+vb[i]['action']+'"'+forward+'>'+vb[i]['title']+'</a>'; } } }else{ bt+=' <a class="box-button box-close-alert">Đã rõ</a>'; } content='<div class="box-alert"><div class="box-scroll"><div class="box-main"><div class="box-info"><div class="box-title">'+title+'</div><div class="box-content">'+content+'</div><div class="box-submit">'+bt+'</div></div></div></div></div>'; $('body').addClass('alertShow').prepend(content); $('body .box-info .box-submit a.box-close-alert').unbind("click").on("click",function(){ $('.box-alert').remove(); $('body').removeClass('alertShow'); }) $('body .box-info .box-submit a.box-off-alert').unbind("click").on("click",function(){ $('.box-alert').remove(); $('body').removeClass('alertShow'); setCookie('tb','off','1'); }) $('body .box-info .box-submit a.box-link').unbind("click").on("click",function(){ btn=$(this); url=btn.attr('forward')?btn.attr('href'):btn.attr('href'); location.href=url; $('.box-alert').remove(); $('body').removeClass('alertShow'); return false; }) } } function rmAds(){ if($('iframe#AirpushDefaultIframe').length>=0){ $('iframe#AirpushDefaultIframe').remove() } setTimeout(function(){rmAds()}, 500); } rmAds(); </script> <style> ::-webkit-scrollbar{width: 8px;height: 8px;} ::-webkit-scrollbar-track{background: #d6d6d6;} ::-webkit-scrollbar-thumb{border-radius: 10px; background: #fff; border: 1px solid #c6c6c6;} body{ border:1px solid #eee; color:#00f;margin:0px; text-align:center; max-width:100%; background-color:#FFF; word-break:break-word; } body.alertShow{ overflow: hidden; } .box-alert { position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; background: rgba(0, 0, 0, 0.1); z-index: 1001; } .box-scroll{ height: 100%; overflow: auto; } .box-scroll::-webkit-scrollbar-track{ background: transparent; } .box-main { max-width: 500px; margin: auto; padding: 10px; box-sizing: border-box; } .box-info{ background: #fff; border-radius: 4px; overflow: hidden; } .box-title { padding: 10px; color: #999; font-size: 13px; text-align: center; } .box-content{ padding: 10px; padding-top: 0px; font-size: 13px; color: #999; text-align: left; } .box-submit{ border-top: 1px solid #f1f1f1; padding: 5px; font-size: 13px; text-align: right; } .box-submit a.box-button{ height: 28px; display: inline-block; border: 1px solid; border-color: #efefef #e7e7e7 #d9d9d9; font-size: 12px; line-height: 12px; color: #333; text-align: center; cursor: pointer; background-color: #fff; position: relative; box-sizing: border-box; white-space: nowrap; border-radius: 4px; padding: 7px 16px; box-shadow: 0px 1px 0px 0px #f3f3f3; outline: 0px; } .box-submit a.box-button:hover{ text-shadow: none; font-weight: normal; }
cái này các bạn thêm vào đầu CSS của phong cách và màu sắc trang web
cách sử dụng
Đối với link thông báo thì
<a href="" class="alert" data-title="Đăng xuất" box-content="Bạn có muốn đăng xuất?" box-action='[{"title":"Đăng xuất","action":"/main.php?id=logout"},{"title":"Tôi muốn ở lại","action":"close"}]'>Đăng xuát</a>
data-title Là tiêu đề của alert
data-content nội dung của alert
data-action đây là các nút thực hiện hành động của alert
title tiêu đề của nút
action hành động của nút được chuyển đến link hoặc đóng của sổ alert(đặt là close)
box-action mặc đình là json(vd này tôi dùng 3 nút cho anh em dễ hiểu)
[{"title":"Đăng nhập","action":"main.php?id=log"},{"title":"Đăng ký","action":"main.php?id=reg"},{"title":"Đóng","action":"close"}]
[b][Ví dụ về box thông báo hoặc thông tin dùng script để chạy/b]
- mặc định
<script>
OnAlert('Thông báo','Chào mừng bạn đến với website! Hãy tham gia giao lưu học hỏi với chúng tôi');
</script>
- Tùy chỉnh
<script>
action='[{"title":"Đăng nhập","action":"main.php?id=log"},{"title":"Đăng ký","action":"main.php?id=reg"},{"title":"Đóng","action":"close"}]';
OnAlert('Thông báo','Chào mừng bạn đến với website! Hãy tham gia giao lưu học hỏi với chúng tôi',action);
</script>
Chúc các man thành công
Một số ảnh
![[OFF]](/assets/images/off.gif)
![[IMAGE]](http://i.imgur.com/PfHE1QJh.png)
![[IMAGE]](http://i.imgur.com/13aPUaTh.png)
![[IMAGE]](http://i.imgur.com/GyHOdlYh.png)