fixedBox固定div漂浮代码支持ie6以上大部分主流浏览器


Posted in Javascript onJune 26, 2014

fixedBox固定div漂浮代码支持ie6以上大部分主流浏览器

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fixedBox</title>
<script id="xcore" type="text/javascript" src="http://www.haiqiancun.com/xWidget-0.1/xcore.js"></script>
<style>
*{margin:0px;padding:0px;} body{height:3000px;}
</style>
<script>
$(function() { $(".fixedBox").each(function() { 
var self = $(this); 
var id = self.attr("id") || 'fixedBox_' + Math.round(Math.random() * 100000); self.attr("id", id); 
var fb = $("#" + id); 
var mt = Math.floor(fb.css("margin-top").substring(2, 0)) || 0; 
var cd = $('<div style="height:' + fb.outerHeight() + 'px;display:none;' + fb.attr("style") + '"> </div>'); fb.after(cd); fb.css({
'z-index': 999
}).data({
'top': fb.offset().top,
'left': fb.offset().left
}); $(window).scroll(function() { 
var pt = fb.data('top'); 
var pl = fb.data('left'); var st = $(document).scrollTop() - 10; 
var h = $(document).height(); 
if (st > pt || st == pt) { cd.show(); 
if ((st + self.outerHeight()) > h) { self.css({
position: 'fixed',
top: (h - (st + self.outerHeight()))
}); 
} else { self.css({
position: 'fixed',
top: 0 - mt
}); 
} 
} else { cd.hide(); self.css({
position: 'relative',
top: 0
}); 
} 
}) 
}) 
}) 
</script>
</span>
</head>
<body>
<div style="width:90%;margin:0px auto;">
<div class="fixedBox" style="margin-top:50px; width:100%; overflow:hidden;background:#fff; font-size:12px;">
<script> $(function(){ $(".fixedBox").each(function(){ 
var self= $(this); var id = self.attr("id")||'fixedBox_'+Math.round(Math.random()*100000);
self.attr("id",id); var fb = $("#"+id); var mt = Math.floor(fb.css("margin-top").substring(2,0))||0;
var cd = $('<div style="width:100%;height:'+fb.outerHeight()+'px;display:none;'+fb.attr("style")+'"> </div>');
fb.after(cd); fb.css({'z-index':999}).data({'top':fb.offset().top,'left':fb.offset().left});
$(window).scroll(function(){ var pt = fb.data('top'); var pl = fb.data('left');
var st = $(document).scrollTop()-10; var h = $(document).height(); if(st>pt||st==pt){
cd.show(); if((st+self.outerHeight())>h){ self.css({position:'fixed',top:(h-(st+self.outerHeight()))});
}else{ self.css({position:'fixed',top:0-mt}); } }else{ cd.hide(); self.css({position:'relative',top:0});
} }) }) }) </script>
</div>
例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例子例
</div>
</body>

</html>
Javascript 相关文章推荐
javascript AOP 实现ajax回调函数使用比较方便
Nov 20 Javascript
js汉字排序问题 支持中英文混排,兼容各浏览器,包括CHROME
Dec 20 Javascript
JavaScript将数据转换成整数的方法
Jan 04 Javascript
jqueryUI里拖拽排序示例分析
Feb 26 Javascript
jQuery+PHP+MySQL二级联动下拉菜单实例讲解
Oct 27 Javascript
JS中的数组方法笔记整理
Jul 26 Javascript
Vue.js每天必学之构造器与生命周期
Sep 05 Javascript
JS基于面向对象实现的拖拽功能示例
Dec 20 Javascript
js中对象与对象创建方法的各种方法
Feb 27 Javascript
angular6根据environments配置文件更改开发所需要的环境的方法
Mar 06 Javascript
VUE 组件转换为微信小程序组件的方法
Nov 06 Javascript
Vue实现tab导航栏并支持左右滑动功能
Jun 28 Vue.js
js实现回放拖拽轨迹从过程上进行分析
Jun 26 #Javascript
JS的事件绑定深入认识
Jun 26 #Javascript
jquery 页眉单行信息滚动显示实现思路及代码
Jun 26 #Javascript
jquery的clone方法应用于textarea和select的bug修复
Jun 26 #Javascript
document.forms用法示例介绍
Jun 26 #Javascript
JS获取当前日期时间并定时刷新示例
Mar 04 #Javascript
使用ajaxfileupload.js实现ajax上传文件php版
Jun 26 #Javascript
You might like
php 过滤英文标点符号及过滤中文标点符号代码
2014/06/12 PHP
PHP使用Redis实现Session共享的实现示例
2019/05/12 PHP
百度留言本js 大家可以参考下
2009/10/13 Javascript
jQuery 下拉列表 二级联动插件分享
2012/03/29 Javascript
IE、FF、Chrome浏览器中的JS差异介绍
2013/08/13 Javascript
jquery选择器之层级过滤选择器详解
2014/01/27 Javascript
用队列模拟jquery的动画算法实例
2015/01/20 Javascript
JavaScript学习笔记之JS对象
2015/01/22 Javascript
简介JavaScript中的getUTCFullYear()方法的使用
2015/06/10 Javascript
基于Jquery和html5的7款个性化地图插件
2015/11/17 Javascript
浅谈js中的变量名和函数名重名
2017/02/13 Javascript
JS实现的模仿QQ头像资料卡显示与隐藏效果
2017/04/07 Javascript
微信小程序template模板实例详解
2017/10/27 Javascript
详解vue移动端日期选择组件
2018/02/22 Javascript
vue计算属性computed的使用方法示例
2019/03/13 Javascript
浅谈Vue.js组件(二)
2019/04/09 Javascript
微信小程序整个页面的自动适应布局的实现
2020/07/12 Javascript
Python中正则表达式的用法实例汇总
2014/08/18 Python
Python制作爬虫采集小说
2015/10/25 Python
python使用wmi模块获取windows下的系统信息 监控系统
2015/10/27 Python
Python实现将罗马数字转换成普通阿拉伯数字的方法
2017/04/19 Python
Python基于whois模块简单识别网站域名及所有者的方法
2018/04/23 Python
python write无法写入文件的解决方法
2019/01/23 Python
对DJango视图(views)和模版(templates)的使用详解
2019/07/17 Python
Python PIL图片添加字体的例子
2019/08/22 Python
给我一面国旗 python帮你实现
2019/09/30 Python
莫斯科绝对前卫最秘密的商店:SVMoscow
2017/10/23 全球购物
美国时尚假发购物网站:Wigsbuy
2019/04/06 全球购物
应用服务器有那些
2012/01/19 面试题
销售找工作求职信
2013/12/20 职场文书
网络编辑岗位职责范本
2014/02/10 职场文书
安全标语口号
2014/06/09 职场文书
公司活动总结怎么写
2014/06/25 职场文书
审计班子对照检查材料
2014/08/27 职场文书
向国旗敬礼活动小结
2014/09/27 职场文书
聘用合同范本
2015/09/21 职场文书