Heim  >  Artikel  >  Web-Frontend  >  层的位置问题_html/css_WEB-ITnose

层的位置问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:43:49797Durchsuche

本帖最后由 u010766076 于 2013-05-30 23:37:35 编辑

JavaScript CSS html

3个span A B C,通过JS设置他的固定位置
设置加载和改变大小的时候调用
用的IE9。
页面加载时只能看到样式表的效果,JS没效果。
这样影响排版吗??????????????????????????????
难道刚开始看到是一个样子,调整浏览器大小,在换一种样子吗????????



html
A
B
C

CSS
#A{
background:red;
position:absolute;
display:inline-block;
left: 95%;
}
#B{
background:red;
position:absolute;
display:inline-block;
left:90%;

}
#C{
background:red;
position:absolute;
display:inline-block;
left:85%;
}

JS
function login(){
  var A= document.getElementById("A");
  A.style.left = (document.documentElement.clientWidth-40)+"px";
  var B= document.getElementById("B");
  B.style.left = (document.documentElement.clientWidth-80)+"px";
  var C= document.getElementById("C");
  C.style.left = (document.documentElement.clientWidth-120)+"px";
}


window.onload=login;
window.onresize=login;

个人觉得是页面加载时提示是否启用JS脚本的问题。
求解决

回复讨论(解决方案)

window.onresize最好放到window.onload函数里边。
window.onload=login;

function login(){
   var A= document.getElementById("A");
   A.style.left = (document.documentElement.clientWidth-40)+"px";
   var B= document.getElementById("B");
   B.style.left = (document.documentElement.clientWidth-80)+"px";
   var C= document.getElementById("C");
   C.style.left = (document.documentElement.clientWidth-120)+"px";

    window.onresize=login;
 }

 

初步断定,你是不是禁用脚本了

初步断定,你是不是禁用脚本了
这个是正解啊,确实有这东西,我去选项里面设置了,没用

window.onresize最好放到window.onload函数里边。
window.onload=login;

function login(){
   var A= document.getElementById("A");
   A.style.left = (document.documentElement.clientWidth-40)+"px";
   var B= document.getElementById("B");
   B.style.left = (document.documentElement.clientWidth-80)+"px";
   var C= document.getElementById("C");
   C.style.left = (document.documentElement.clientWidth-120)+"px";

    window.onresize=login;
 }

 

现在的问题只是初始的时候只有css的效果,并没有login函数的效果。

测试了一遍,写到函数里面不会调用,调用的话也只是加载的时候调用一次

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn