<!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>
<title> Test Property </title>
<meta name="generator" content="editplus" />
</head> <body>
<script type="text/javascript">
<!--
var isIE = (document.all) ? true : false; var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6); var $ = function(sId){
return "string" == typeof(sId) ? document.getElementById(sId) : sId;
} var Bind = function(object, fun){
return function() {
return fun.apply(object, arguments);
}
} function addEventHandler(oTarget, sEventType, fnHandler){
if(oTarget.addEventListener){
oTarget.addEventListener(sEventType, fnHandler, false);
}else if(oTarget.attachEvent){
oTarget.attachEvent("on" + sEventType, fnHandler);
}else{
oTarget["on" + sEventType] = fnHandler;
}
} var isSafa = (window.openDatabase) ? true : false; var TestProper = function(){
}; TestProper.prototype = {
// 创建广告
CreateBanner: function(){
document.write("<div id='crazy_bannerleft' style='width:90px;border:2px solid red;height:240px;z-index:12299;onMouseDown='return false;'></div>");
document.write("<div id='crazy_bannerright' style='width:90px;height:240px;border:2px solid red;z-index:12299;onMouseDown='return false;'></div>");
this.LeftBanner = $("crazy_bannerleft");
this.RightBanner = $("crazy_bannerright");
}, // 设置条幅的滚动程序
SetBannerFixed: function(){
$("crazy_bannerright").style.top = (d.scrollTop+d.clientHeight-$("crazy_bannerright").offsetHeight)+"px";
$("crazy_bannerright").style.left = (d.scrollLeft+d.clientWidth-$("crazy_bannerright").offsetWidth)+"px";
$("crazy_bannerleft").style.top = (d.scrollTop+d.clientHeight-$("crazy_bannerleft").offsetHeight)+"px";
$("crazy_bannerleft").style.left = (d.scrollLeft)+"px";
}, Init: function(){
// Safari不进行操作
if(!!isSafa) return;
var $d = document.compatMode == "BackCompat" ? d = document.body : d = document.documentElement;
this.CreateBanner();
this.LeftBanner.style.position = !isIE6 ? "fixed" : "absolute";
this.RightBanner.style.position = !isIE6 ? "fixed" : "absolute";
if(isIE6) {
addEventHandler(window, "scroll", this.SetBannerFixed);
}
addEventHandler(window, "load", this.SetBannerFixed);
addEventHandler(window, "resize", this.SetBannerFixed);
}
} var Test = new TestProper();
Test.Init();
//-->
</script>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
</body>
</html>要求很简单,就是让两个DIV一直浮动在页面左右的最底端。
现在的代码在IE6和Chrome浏览器下测试没问题 但在FF下测试有问题,就是在页面resize的时候 DIV会消失请朋友们指点下。有时间的 再看下
http://topic.csdn.net/u/20090505/16/f63f9830-a4b6-4ab5-ba41-ba70fcdb471b.html?seed=630934394&t=fudgtzhb
或者说 你这问题太简单 我不惜得解决 或者说 这问题太难没法解决那样我好死心啊
没有出现你说问题啊,IE、FF都是停在页面的底部,我的FF是3.0.9的
楼上的兄弟 ,估计我说漏了
你用火狐 打开后 拖动滚动条 然后再Resize 看看
右底的.... ie ff没问题 没有Chrome
<body><div id="ss" style="height:200px; width:200px; background-color:#FF0000; position:absolute"></div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></body>
<script>
var div = document.getElementById("ss")
var top = document.body.clientHeight-div.offsetHeight
function change()
{
div.style.left=document.body.clientWidth-div.offsetWidth //左底=0
div.style.top =document.body.clientHeight-div.offsetHeight+document.body.scrollTop
top = document.body.clientHeight-div.offsetHeight
}
change()
window.onresize=change
window.onscroll=function(){div.style.top=top+document.body.scrollTop}
</script>
</html>
居中的
<body><div id="ss" style="height:200px; width:200px; background-color:#FF0000; position:absolute"></div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></body>
<script>
var div = document.getElementById("ss")
var top = (document.body.clientHeight-div.offsetHeight)/2
var left = (document.body.clientWidth-div.offsetWidth)/2
function change()
{
div.style.left=(document.body.clientWidth-div.offsetWidth)/2
div.style.top =(document.body.clientHeight-div.offsetHeight)/2+document.body.scrollTop
top = (document.body.clientHeight-div.offsetHeight)/2
left = (document.body.clientWidth-div.offsetWidth)/2
}
change()
window.onresize=change
window.onscroll=function(){div.style.top=top+document.body.scrollTop}
</script>
// Safari不进行操作
if(!!isSafa) return;
var $d = document.compatMode == "BackCompat" ? d = document.body : d = document.documentElement;
this.CreateBanner();
this.LeftBanner.style.position = !isIE6 ? "fixed" : "absolute";
this.RightBanner.style.position = !isIE6 ? "fixed" : "absolute";
if(isIE6) {
addEventHandler(window, "scroll", this.SetBannerFixed);
}
//addEventHandler(window, "load", this.SetBannerFixed);
//addEventHandler(window, "resize", this.SetBannerFixed);
$("crazy_bannerright").style.bottom = 0;
$("crazy_bannerright").style.right = 0;
$("crazy_bannerleft").style.bottom = 0;
$("crazy_bannerleft").style.left = 0;
}
看来你还没明白fixed的作用啊
嗯 左下 简单的 我主要是试了下fixed的用法你帮我看下7楼的要求
怎么变成ie6了
之前他还说的是FF好的,IE6有问题到这里也一会FF一会IE6的
cloudgamer 不好意思 刚才你改完后 我知道问题所在了。。
刚才问的IE6问题 我自己解决了。主要现在要兼容所有浏览器 ,所以 上一个贴子的问题 还有小毛病
一会FF一会IE6的能不晕吗?
// 如果 我想调用this._bannerfixed(obj)并且 想传个object对象 给SetBannerFixed()应该怎么去写
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
}
}用这个bind就可以了
var Bind = function(object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
}
}SetFixed: function(obj){
alert(obj)
}this._fixed = Bind(this, function(){this.isCenter ? this.SetCenter() : this.SetFixed();})this._fixed(Object);
这样用么?
this._fixed = Bind(this, function(){this.isCenter ? this.SetCenter() : this.SetFixed();})this.isMaxFixed && addEventHandler(window, "scroll", this._fixed("dddd"));SetFixed: function(obj){
alert(obj)
}打印的是undefined
你要把参数传进去嘛
//this._fixed("dddd")这样是不可以的 因为addEventHandler只能传句柄this._fixed
是不是应该怎样 弄个闭包解决?
if(isIE6) {
this.isMaxFixed && addEventHandler(window, "scroll", (function(obj){
return function(){
oThis._fixed(obj);
}
})(this.Container));
}也真繁琐
这样应该也可以