js右下彈出窗口代碼加定時

javascript代碼:

// JavaScript Document
var url_xinxi=getxinxi.php; //獲取窗口顯示內容的URL;
function tips_pop(){
var MsgPop=document.getElementById("winpop");
var popH=parseInt(MsgPop.style.height);//將對象的高度轉化爲數字
if (popH==0){
MsgPop.style.display="block";//顯示隱藏的窗口
$.getJSON(url_xinxi, { name: "John", time: "2pm" },
function(data){
if(data.status=='sccess'){
$("#winpop").html(data.msg);
show=setInterval("changeH('up')",50);
}
});
}
else {
hide=setInterval("changeH('down')",50);
}
}
function changeH(str) {
var MsgPop=document.getElementById("winpop");
var popH=parseInt(MsgPop.style.height);
if(str=="up"){
if (popH<=140){
MsgPop.style.height=(popH+4).toString()+"px";
var topHeight2 = document.documentElement.scrollTop + document.documentElement.clientHeight - popH-4;
$("#winpop").css("top",topHeight2+"px");
}
else{
clearInterval(show);
}
}
if(str=="down"){
if (popH>=4){
MsgPop.style.height=(popH-4).toString()+"px";
}
else{
clearInterval(hide);
MsgPop.style.display="none"; //隱藏DIV
}
}
}
function tips_pop2(str) {
document.getElementById('winpop').style.height='0px';
document.getElementById('winpop').style.display="none";
tips_pop();
setTimeout("tips_pop2()",60000);
}
$(document).ready(function(){
if($("#winpop").length>0){
//第一次加載執行
window.onload=function(){//加載
document.getElementById('winpop').style.height='0px';
setTimeout("tips_pop()",3000);//3秒後調用tips_pop()這個函數
}
//每一分鐘執行
$(function () {
setTimeout("tips_pop2()",60000);
});
//滾動條
$(window).scroll( function() {
var MsgPop=document.getElementById("winpop");
var popH=parseInt(MsgPop.style.height);//將對象的高度轉化爲數字
var topHeight = document.documentElement.scrollTop + document.documentElement.clientHeight - popH;
$("#winpop").css("top",topHeight+"px");
});
}
});

html代碼:


<html>
<style>
/*右下信息提示*/
#winpop { width:264px; height:0px;position:absolute; right:0; bottom:0; border:1px solid #66CC33; margin:0; padding:0px; overflow:hidden; display:none;}
#winpop .title { width:100%; height:28px; line-height:28px; background:#66CC33;text-align:left; font-size:12px; color:#ffffff;padding-left:10px; background:url(../../images/icon/yx_title.gif);}
#winpop .con { width:260; min-height:110px;line-height:20px; padding:10px; text-align:left; font-size:12px; color:#000000; text-decoration:none; background:#FFFFFF; overflow:hidden; }
#silu { font-size:12px; color:#666; position:absolute; right:0; text-align:right; text-decoration:underline; line-height:22px;}
.close { position:absolute; right:4px; top:-1px; color:#FFF; cursor:pointer}
</style>
<body>
<!--彈出窗-->
<div id="winpop">
</div>
<!--end-->
</body>
</html>

說明:
定義和用法
setInterval() 方法可按照指定的週期(以毫秒計)來調用函數或計算表達式。   setInterval() 方法會不停地調用函數,直到 clearInterval() 被調用或窗口被關閉。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的參數。
語法
setInterval(code,millisec[,"lang"])   
參數 描述
code 必需。要調用的函數或要執行的代碼串。
millisec 必需。週期性執行或調用 code 之間的時間間隔,以毫秒計。
返回值
一個可以傳遞給 Window.clearInterval() 從而取消對 code 的週期性執行的值。
setTimeout() 只執行 code 一次。如果要多次調用,請使用 setInterval() 或者讓 code 自身再次調用 setTimeout()。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章