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 相关文章推荐
JQuery this 和 $(this) 的区别
Aug 23 Javascript
28个JS验证函数收集
Mar 02 Javascript
添加JavaScript重载函数的辅助方法2
Jul 04 Javascript
jquery 插件开发备注
Aug 27 Javascript
js工具方法弹出蒙版
May 08 Javascript
JavaScript加强之自定义event事件
Sep 21 Javascript
JavaScript实现梯形乘法表的方法
Apr 25 Javascript
jQuery无刷新分页完整实例代码
Oct 27 Javascript
javascript完美实现给定日期返回上月日期的方法
Jun 15 Javascript
详解babel升级到7.X采坑总结
May 12 Javascript
vue ajax 拦截原理与实现方法示例
Nov 29 Javascript
JavaScript indexOf()原理及使用方法详解
Jul 09 Javascript
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 memcache扩展的三种安装方法
2009/04/26 PHP
php数组索引与键值操作技巧实例分析
2015/06/24 PHP
Thinkphp 中 distinct 的用法解析
2016/12/14 PHP
php图片合成方法(多张图片合成一张)
2017/11/25 PHP
PHP日期和时间函数的使用示例详解
2020/08/06 PHP
js中的时间转换—毫秒转换成日期时间的示例代码
2014/01/26 Javascript
深入浅析AngularJS和DataModel
2016/02/16 Javascript
jQuery实现每隔几条元素增加1条线的方法
2016/06/27 Javascript
使用get方式提交表单在地址栏里面不显示提交信息
2017/02/21 Javascript
NodeJS链接MySql数据库的操作方法
2017/06/27 NodeJs
Javascript实现base64的加密解密方法示例
2017/06/27 Javascript
js自定义弹框插件的封装
2020/08/24 Javascript
javascript将list转换成树状结构的实例
2017/09/08 Javascript
python时间整形转标准格式的示例分享
2014/02/14 Python
Python中实现参数类型检查的简单方法
2015/04/21 Python
Python中动态创建类实例的方法
2017/03/24 Python
Win10环境python3.7安装dlib模块趟过的坑
2019/08/01 Python
Python 共享变量加锁、释放详解
2019/08/28 Python
python对象销毁实例(垃圾回收)
2020/01/16 Python
Python实现鼠标自动在屏幕上随机移动功能
2020/03/14 Python
jupyter notebook 参数传递给shell命令行实例
2020/04/10 Python
pandas to_excel 添加颜色操作
2020/07/14 Python
python从Oracle读取数据生成图表
2020/10/14 Python
Alba Moda德国网上商店:意大利时尚女装销售
2016/11/14 全球购物
美国亚马逊旗下时尚女装网店:SHOPBOP(支持中文)
2020/10/17 全球购物
编写一个类体现构造,公有,私有方法,静态,私有变量
2013/08/10 面试题
配件采购员岗位职责
2013/12/03 职场文书
大一学生的职业生涯规划书范文
2014/01/19 职场文书
青年教师典范事迹材料
2014/01/31 职场文书
《蒲公英》教学反思
2014/02/28 职场文书
个人工作表现评语
2014/04/30 职场文书
2014年教师节演讲稿范文
2014/09/10 职场文书
工作检讨书500字
2014/10/19 职场文书
小学四年级班主任工作经验交流材料
2015/11/02 职场文书
《草虫的村落》教学反思
2016/02/20 职场文书
门面租赁合同范文
2019/08/06 职场文书