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 相关文章推荐
js实现的网页颜色代码表全集
Jul 17 Javascript
JavaScript XML实现两级级联下拉列表
Nov 10 Javascript
js实现无需数据库的县级以上联动行政区域下拉控件
Aug 14 Javascript
Js base64 加密解密介绍
Oct 11 Javascript
使用百度地图api实现根据地址查询经纬度
Dec 11 Javascript
js使用cookie记录用户名的方法
Nov 26 Javascript
javascript 正则表达式分组、断言详解
Apr 20 Javascript
原生JS封装animate运动框架的实例
Oct 12 Javascript
React Native中Navigator的使用方法示例
Oct 13 Javascript
JS实现select选中option触发事件操作示例
Jul 13 Javascript
详解解决Vue相同路由参数不同不会刷新的问题
Oct 12 Javascript
jQuery实现动态加载瀑布流
Sep 01 jQuery
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
第十五节--Zend引擎的发展
2006/11/16 PHP
PHPMailer邮件类利用smtp.163.com发送邮件方法
2008/09/11 PHP
yii框架配置默认controller和action示例
2014/04/30 PHP
在Yii2中使用Pjax导致Yii2内联脚本载入失败的原因分析
2016/03/06 PHP
PHP levenshtein()函数用法讲解
2019/03/08 PHP
Laravel配置全局公共函数的方法步骤
2019/05/09 PHP
完整显示当前日期和时间的JS代码
2007/09/17 Javascript
中止javascript执行的方法
2014/02/14 Javascript
php和js对数据库图片进行等比缩放示例
2014/04/28 Javascript
JS获取浏览器语言动态加载JS文件示例代码
2014/10/31 Javascript
JS实现的论坛Ajax打分效果完整实例
2015/10/31 Javascript
基于JavaScript代码实现兼容各浏览器的设为首页和加入收藏
2016/01/07 Javascript
基于jQuery实现的查看全文功能【实用】
2016/12/11 Javascript
BootStrop前端框架入门教程详解
2016/12/25 Javascript
详解本地Node.js服务器作为api服务器的解决办法
2017/02/28 Javascript
JS HTML图片显示Canvas 压缩功能
2017/07/21 Javascript
JavaScript屏蔽Backspace键的实现代码
2017/11/02 Javascript
前端vue-cli项目中使用img图片和background背景图的几种方法
2019/11/13 Javascript
微信小程序pinker组件使用实现自动相减日期
2020/05/07 Javascript
原生js实现弹幕效果
2020/11/29 Javascript
[32:26]EG vs IG 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
python opencv实现任意角度的透视变换实例代码
2018/01/12 Python
python微信跳一跳系列之棋子定位像素遍历
2018/02/26 Python
解决pycharm 安装numpy失败的问题
2019/12/05 Python
python super用法及原理详解
2020/01/20 Python
python 函数中的参数类型
2020/02/11 Python
Python基于os.environ从windows获取环境变量
2020/06/09 Python
Python同时处理多个异常的方法
2020/07/28 Python
python录音并调用百度语音识别接口的示例
2020/12/01 Python
canvas进阶之如何画出平滑的曲线
2018/10/15 HTML / CSS
英国时尚首饰品牌:Missoma
2020/06/29 全球购物
电气自动化大学生求职信
2013/10/16 职场文书
公司授权委托书范本
2014/04/03 职场文书
国庆节促销广告语2014
2014/09/19 职场文书
2014年小学数学工作总结
2014/12/12 职场文书
团员个人年度总结
2015/02/26 职场文书