DIV CSS 佈局教程網

動手做:用 jQuery 實現右下角滑出的提示公告框
編輯:JQuery特效代碼     

網站營運時,常有需要向訪客推送公告或提示的時刻。與其用惱人的彈窗打斷瀏覽,不如做一個安靜滑入右下角的提示框,既醒目又不叨擾。下面這份完整範例帶你從零打造這樣一個效果。

整體思路很簡單:用 CSS 把提示層固定在右下角,再利用 jQuery 在頁面載入後透過 animate() 讓它從下方平滑滑出,最後綁定關閉按鈕即可。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript" src="https://www.chinahds.com/js/jquery-1.8.2.min.js" ></script>
<title>彈出提示框右下角顯示</title>
<style type="text/css">
body{ margin:0px;padding:0px; height:5000px; }
.botk{right:5px;position:fixed;width:100px;_position:absolute; _top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); z-index:999; height:100px;filter: Alpha(opacity=90);-moz-opacity:.9;opacity:0.9;background:#ffffff; color:#ffffff; bottom:5px;}
.botts{width:100px; height:100px; position:absolute; z-index:9999;background:#000000;}
#adclose{width:20px; height:20px; position:absolute; cursor:pointer; z-index:99999}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
var wintopfir=$(".botk").height();
var wintopsec=wintopfir-100;
$("#bottomad").css({top:wintopfir+"px"});
$("#bottomad").animate({top:wintopsec+"px" }, 2000);
$("#adclose").click( function () { $("#bottomad").hide(); });
});
</script>
</head>
<body>
<div class="botk">
<div id="bottomad" class="botts">
<div id="adclose">X</div>
一個jquery實現的右下角慢慢彈出提示公告,學習做的。大家給意見哈。
</div>
</div>
</body>
</html>

值得留意的是樣式中的兼容性處理:position:fixed 讓提示框固定於視窗,而下面那行帶底線的 _position 與表達式則是針對舊版 IE 的 hack。此外,透過 animate() 在兩秒內改變 top 值,就能獲得平順的滑出手感;點擊關閉按鈕時呼叫 hide() 收合,互動便完整了。你可以依需求替換提示文字與樣式,讓它更貼合自己的網站調性。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved