本例为大家分享的是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>
最新资讯
反直觉!新方法或让AI模型拥有"联想"力,甚至能识别从未见过的事物

反直觉!新方法或让AI

一种新的方法正在让人工智能模型获得人类的 “联想”
代码老矣,尚能跑否?

代码老矣,尚能跑否?

研究人员如何基于原始论文和自行编写的开源代码来复现
够硬!这虫子汽车都压不死

够硬!这虫子汽车都压不

虫子到底能有多硬?《自然》的新研究展示了一种超抗压的
14岁中学生找到有望治疗新冠的药物,获得北美科研竞赛大奖

14岁中学生找到有望治

1918年美国堪萨斯州莱利堡的临时医院。图片来源:Associ
乳腺癌发病率上升,哪些因素起了推动作用?

乳腺癌发病率上升,哪些

乳腺癌的发生,与多种因素有关。随着对乳腺癌研究的深入
李在镕:三星所有人都会珍惜李健熙的记忆

李在镕:三星所有人都会

李在镕表示,“我们三星的所有人都会珍惜他的记忆,并感谢
最新文章
详解Vue的ref特性的使用

详解Vue的ref特性的使

这篇文章主要介绍了详解Vue的ref特性的使用,文中通过
vue学习笔记之slot插槽基本用法实例分析

vue学习笔记之slot插

这篇文章主要介绍了vue学习笔记之slot插槽基本用法,结
vue跳转方式(打开新页面)及传参操作示例

vue跳转方式(打开新页

这篇文章主要介绍了vue跳转方式(打开新页面)及传参操作,
vue学习笔记之过滤器的基本使用方法实例分析

vue学习笔记之过滤器

这篇文章主要介绍了vue学习笔记之过滤器的基本使用方
js获取本日、本周、本月的时间代码

js获取本日、本周、本

本篇文章给大家分享的内容是利用js如何获取本日、本周
node crawler如何添加promise支持

node crawler如何添加

这篇文章主要介绍了node crawler如何添加promise支持,