代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
兼容性非常好的js右下角与漂浮广告代码
时间:2021-04-04 10:14:58 | 栏目:
JavaScript代码
| 点击:次
兼容ie6 7 8 ,ff3.5 3.6,chrome 4.1.2,safari
重新修正
1.滚动时抖动的问题,主要体现在ff3.6上
2.加入了ie6下的固定
3.分成了两个块,xhtml,html解析
4.随着屏幕大小而变动
兼容ie6 7 8
ff3.5 3.6
chrome 4.1.2
safari
xhtml1.0解析
<!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=gbk" /> <title>Untitled Document</title> <style> html,body{ padding:0; margin:0; } </style> </head> <body> <div id="aa" style="width:100px;height:100px;background:#c0c0c0;" >我在随平滚</div> <div id="bb" style="width:100px;height:100px;background:#c0c0c0;" >我静止不动</div> <div style="width:100%;height:1500px;background:#000"></div> <div style="width:100%;height:1500px;background:green"></div> <div style="width:100%;height:1500px;background:red"></div> </body> </html> <script> function scrollx(p){ var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie6 = /msie 6/i.test(navigator.userAgent),style,timer; if(o){ o.style.cssText +=";position:"+(p.f&&!ie6?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0'); if(p.f&&ie6){ o.style.cssText +=';left:expression(documentElement.scrollLeft + '+(p.l==undefined?dd.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(documentElement.scrollTop +'+(p.t==undefined?dd.clientHeight-o.offsetHeight:p.t)+'+ "px" );'; dd.style.cssText +=';background-image: url(about:blank);background-attachment:fixed;'; }else{ if(!p.f){ w.onresize = w.onscroll = function(){ clearInterval(timer); timer = setInterval(function(){ //双选择为了修复chrome 下xhtml解析时dd.scrollTop为 0 var st = (dd.scrollTop||db.scrollTop),c; c = st - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||dd.clientHeight)-o.offsetHeight); if(c!=0){ o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px'; }else{ clearInterval(timer); } },10) } } } } } scrollx({ id:'aa' }) scrollx({ id:'bb', l:0, t:200, f:1 }) /* id 你要滚动的内容的id l 横坐标的位置 不写为紧贴右边 t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边 f 1表示固定 不写或者0表示滚动 */ </script>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
html4.01解析
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>Untitled Document</title> <style> html,body{ padding:0; margin:0; } </style> </head> <body> <div id="aa" style="width:100px;height:100px;background:#c0c0c0;" >我在随平滚</div> <div id="bb" style="width:100px;height:100px;background:#c0c0c0;" >我静止不动</div> <div style="width:100%;height:1500px;background:#000"></div> <div style="width:100%;height:1500px;background:green"></div> <div style="width:100%;height:1500px;background:red"></div> </body> </html> <script> function scroll(p){ var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie = /msie/i.test(navigator.userAgent),style,timer; if(o){ //ie8下position:fixed下top left失效 o.style.cssText +=";position:"+(p.f&&!ie?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0'); if(p.f&&ie){ o.style.cssText +=';left:expression(body.scrollLeft + '+(p.l==undefined?db.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(body.scrollTop +'+(p.t==undefined?db.clientHeight-o.offsetHeight:p.t)+'+ "px" );' db.style.cssText +=";background-image:url(about:blank);background-attachment:fixed;" }else{ if(!p.f){ w.onresize = w.onscroll = function(){ clearInterval(timer); timer = setInterval(function(){ var st = db.scrollTop,c; c = st - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||db.clientHeight)-o.offsetHeight); if(c!=0){ o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px'; }else{ clearInterval(timer); } },10) } } } } } scroll({ id:'aa' }) scroll({ id:'bb', l:0, t:200, f:1 }) /* id 你要滚动的内容的id l 横坐标的位置 不写为紧贴右边 t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边 f 1表示固定 不写或者0表示滚动 */ </script>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
javascript上下左右定时滚动插件
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
相关文章
11-08
兼容浏览器的js事件绑定函数(详解)
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长