PHP程序员站--PHP编程开发平台
 当前位置:主页 >> 网页制作 >> Javascript >> 

网页右下角浮动窗口代码

网页右下角浮动窗口代码

来源:phperz.com  作者:phperz.com  发布时间:2012-02-22
网页右下角浮动窗口代码,你也可以改成右下角浮动广告,效果如本站的右下角实时热点 如图: 代码: 以下为引用的内容: //浮动 document.write('style type=text/css'); document.write('#msg_win{border:1px solid #1D5892;background:#fff;width:300px;position:absolute

网页右下角浮动窗口代码,你也可以改成右下角浮动广告,效果如本站的右下角"实时热点"

如图:

 

代码:

 

以下为引用的内容:
//浮动
document.write('<style type="text/css">');
document.write('#msg_win{border:1px solid #1D5892;background:#fff;width:300px;position:absolute;right:0;font-size:12px;font-family:Arial;margin:0px;display:none;overflow:hidden;z-index:99;}');
document.write('#msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;color:#fff}');
document.write('.icos a{float:left;color:#fff;margin:1px;text-align:center;font-weight:bold;width:14px;height:22px;line-height:22px;padding:1px;text-decoration:none;font-family:webdings;}');
document.write('.icos a:hover{color:#fff;}');
document.write('#msg_title{background:#1D5892;border-bottom:1px solid #3C7FAF;border-top:1px solid #FFF;border-left:1px solid #FFF;color:#fff;height:25px;line-height:25px;text-indent:5px;}');
document.write('#msg_content{margin:5px;margin-right:0;width:297px;height:160px;overflow:hidden;}');
document.write('#msg_content div{line-height:20px;height:20px;overflow:hidden;}');
document.write('</style>');

document.write('<div id="msg_win" style="display:none;top:490px;visibility:visible;opacity:1;">');
document.write('<div class="icos"><a id="msg_min" title="最小化" href="javascript:void 0" target="_self">_</a><a id="msg_close" title="关闭" href="javascript:void 0" target="_self">×</a></div>');
document.write('<div id="msg_title">实时热点资讯 - PHP程序员站</div>');
document.write('<div id="msg_content"><div>·<a href="/php/introduction/102615P20081580.html" target="_blank">常用php代码示例</a></div><div>·<a href="/php-news/news/0103162W201216287.html" target="_blank">WP7开发者晒收入 2011年挣了6万美元</a></div><div>·<a href="/database/MySQL/0R22D620102686.html" target="_blank">mysql left join,right join,inner join用法</a></div><div>·<a href="/web-design/javascript/0F3350620113506.html" target="_blank">可拖放的树形控件 jQuery Simple Tree</a></div><div>·<a href="/php/php-article/01045922008592.html" target="_blank">PHP中删除目录的三种方法</a></div><div>·<a href="/php/php-article/120S2200732.html" target="_blank">Apache PHP MySQL Zend GD OpenSSL vsftpd 完全编译安装手册</a></div><div>·<a href="/database/MySQL/110cT220119842.html" target="_blank">mysql 导入导出数据库以及函数,存储过程方法</a></div><div>·<a href="/php-news/b/1/20120221831.html" target="_blank">iOS 5.0.1 Bug:可绕过密码进入联系人名单/拨打电话</a></div><div>·<a href="/phpcms/phpcms/101B91120116911.html" target="_blank">30个国外PHP开源CMS内容管理系统推荐</a></div><div>·<a href="/web-design/CSS/0Z51b520091985.html" target="_blank">z-index 最大值</a></div></div>');
document.write('</div>');


var Message={
set: function() {//最小化与恢复状态切换
var set=this.minbtn.status == 1?[0,1,'block',this.char[0],'最小化']:[1,0,'none',this.char[1],'恢复'];
this.minbtn.status=set[0];
this.win.style.borderBottomWidth=set[1];
this.content.style.display =set[2];
this.minbtn.innerHTML =set[3]
this.minbtn.title = set[4];
this.win.style.top = this.getY().top;
},
close: function() {//关闭
this.win.style.display = 'none';
window.onscroll = null;
},
setOpacity: function(x) {//设置透明度
var v = x >= 100 ? '': 'Alpha(opacity=' + x + ')';
this.win.style.visibility = x<=0?'hidden':'visible';//IE有绝对或相对定位内容不随父透明度变化的bug
this.win.style.filter = v;
this.win.style.opacity = x / 100;
},
show: function() {//渐显
clearInterval(this.timer2);
var me = this,fx = this.fx(0, 100, 0.1),t = 0;
this.timer2 = setInterval(function() {
t = fx();
me.setOpacity(t[0]);
if (t[1] == 0) {clearInterval(me.timer2) }


},10);
},
fx: function(a, b, c) {//缓冲计算
var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1;
return function() {return [a += cMath((b - a) * c), a - b]}
},
getY: function() {//计算移动坐标
var d = document,b = document.body, e = document.documentElement;
var s = Math.max(b.scrollTop, e.scrollTop);
var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
var h2 = this.win.offsetHeight;
return {foot: s + h + h2 + 2+'px',top: s + h - h2 - 2+'px'}
},
moveTo: function(y) {//移动动画
clearInterval(this.timer);
var me = this,a = parseInt(this.win.style.top)||0;
var fx = this.fx(a, parseInt(y));
var t = 0 ;
this.timer = setInterval(function() {
t = fx();
me.win.style.top = t[0]+'px';
if (t[1] == 0) {
clearInterval(me.timer);
me.bind();
}
},10);
},
bind:function (){//绑定窗口滚动条与大小变化事件
var me=this,st,rt;
window.onscroll = function() {
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st = setTimeout(function() {
me.win.style.top = me.getY().top;
me.show();
},600);
};
window.onresize = function (){
clearTimeout(rt);
rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
}
},
init: function() {//创建HTML
function $(id) {return document.getElementById(id)};
this.win=$('msg_win');
var set={minbtn: 'msg_min',closebtn: 'msg_close',title: 'msg_title',content: 'msg_content'};
for (var Id in set) {this[Id] = $(set[Id])};
var me = this;
this.minbtn.onclick = function() {me.set();this.blur()};
this.closebtn.onclick = function() {me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];//FF不支持webdings字体
this.minbtn.innerHTML=this.char[0];
this.closebtn.innerHTML=this.char[2];
setTimeout(function() {//初始化最先位置


me.win.style.display = 'block';
me.win.style.top = me.getY().foot;
me.moveTo(me.getY().top);
},0);
return this;
}
};
Message.init();
//end

用法:把上面的 代码copy到文件存为.js文件,在页中调用即可.

浮动窗口js代码下载


延伸阅读:
CSS技巧:子元素浮动后父容器的闭合
CSS教程:清除浮动的方法大全 转
CSS浮动属性Float详解
jQuery跟随浏览器滚动条浮动层效果
jQuery浮动窗口插件 scrollFollow
Tags: 网页   右下角   浮动窗口   代码  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号