标题:[求助]问一个居中问题
只看楼主
xinzheng
Rank: 1
等 级:新手上路
帖 子:193
专家分:0
注 册:2007-7-22
 问题点数:0 回复次数:6 
[求助]问一个居中问题

<script>
var getit = function(n) {
return(document.getElementById(n));
}

var addit = function(n) {
getit('editform').style.visibility = "";
getit('editframe').src = 'add.asp?key=' + n;

}
</script>


<body>
<div style="position:absolute; top:50%; left:50%; margin:-100px 0 0 -150px; visibility: hidden;" id="editform">
<iframe id="editframe" frameborder=0 width=300 scrolling="no" marginheight="0" marginwidth="0" onload="this.style.height = editframe.document.body.scrollHeight" ></iframe>
</div>

<a href="javascript: addit();">填写留言</a>

点填写留言显示iframe可这个iframe不随垂直滚动条而移动,造成一定的麻烦,不知道有没有办法写成永远在显示屏幕的中间

[此贴子已经被作者于2007-8-13 13:28:36编辑过]

搜索更多相关主题的帖子: visibility getit style var 
2007-08-13 13:23
ayue222
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:341
专家分:0
注 册:2007-7-25
得分:0 
<div style="position:absolute; top:50%; left:50%; margin:-100px 0 0 -150px; visibility: hidden;z-index:100;" id="editform">
2007-08-13 14:04
xinzheng
Rank: 1
等 级:新手上路
帖 子:193
专家分:0
注 册:2007-7-22
得分:0 
可能我没表达清楚我的意思!估计我要的效果这种方式办不到!我是想不管垂直滚动条上下滚动,那个iframe总是居屏幕之中
2007-08-13 17:36
vfp00
Rank: 1
等 级:新手上路
帖 子:241
专家分:0
注 册:2006-2-20
得分:0 
<div style="position:absolute; top:50%; left:50%; margin:-100px 0 0 -150px; align=center; visibility: hidden;" id="editform" >

lz試試這樣。
2007-08-13 18:01
sunt88126
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-2
得分:0 

加段js的标签浮动代码?

试试
把它放在标签后面
<script LANGUAGE="JavaScript">
self.onError=null;
currentX = currentY = 0;
whichIt = null;
lastScrollX = 0; lastScrollY = 0;
NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1: 0;
<!-- STALKER CODE -->
function heartBeat() {
if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater.style.pixelTop += percent;
if(NS) document.floater.top += percent;
lastScrollY = lastScrollY + percent;
}
if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater.style.pixelLeft += percent;
if(NS) document.floater.left += percent;
lastScrollX = lastScrollX + percent;
}
}
<!-- /STALKER CODE -->
<!-- DRAG DROP CODE -->
function checkFocus(x,y) {
stalkerx = document.floater.pageX;
stalkery = document.floater.pageY;
stalkerwidth = document.floater.clip.width;
stalkerheight = document.floater.clip.height;
if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;
else return false;
}
function grabIt(e) {
if(IE) {
whichIt = event.srcElement;
while (whichIt.id.indexOf("floater") == -1) {
whichIt = whichIt.parentElement;
if (whichIt == null) { return true; }
}
whichIt.style.pixelLeft = whichIt.offsetLeft;
whichIt.style.pixelTop = whichIt.offsetTop;
currentX = (event.clientX + document.body.scrollLeft);
currentY = (event.clientY + document.body.scrollTop);
} else {
window.captureEvents(Event.MOUSEMOVE);
if(checkFocus (e.pageX,e.pageY)) {
whichIt = document.floater;
StalkerTouchedX = e.pageX-document.floater.pageX;
StalkerTouchedY = e.pageY-document.floater.pageY;
}
}
return true;
}
function moveIt(e) {
if (whichIt == null) { return false; }
if(IE) {
newX = (event.clientX + document.body.scrollLeft);
newY = (event.clientY + document.body.scrollTop);
distanceX = (newX - currentX); distanceY = (newY - currentY);
currentX = newX; currentY = newY;
whichIt.style.pixelLeft += distanceX;
whichIt.style.pixelTop += distanceY;
if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop;
if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft;
if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
event.returnValue = false;
} else {
whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY);
if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset;
if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset;
if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17;
if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17;
return false;
}
return false;
}
function dropIt() {
whichIt = null;
if(NS) window.releaseEvents (Event.MOUSEMOVE);
return true;
}
<!-- DRAG DROP CODE -->
if(NS) {
window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
window.onmousedown = grabIt;
window.onmousemove = moveIt;
window.onmouseup = dropIt;
}
if(IE) {
document.onmousedown = grabIt;
document.onmousemove = moveIt;
document.onmouseup = dropIt;
}
if(NS || IE) action = window.setInterval("heartBeat()",1);
</script>

2007-08-13 18:49
xinzheng
Rank: 1
等 级:新手上路
帖 子:193
专家分:0
注 册:2007-7-22
得分:0 
看不懂太复杂了
2007-08-13 20:34
sunt88126
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-2
得分:0 
这段代码的作用就是让名为"floater"的标签实现浮动效果
即滚动条滚动,floater标签总在屏幕中。
如果想用其他标签名,如你的 editform
只需将所有的“document.floater”改为document.editform即可

这段代码是我以做一个文章评论系统时找的一个特效,发的时候忘记该标签id了
2007-08-13 20:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-162325-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.304392 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved