我想将通常在右侧浮动的 div 移动到绝对位置(由 js 确定),然后返回到其初始位置。
第一部分已经工作并且依赖于设置对象的“style.”标签..类似于
mytarget.style.position="absolute";
mytarget.style.top="50px";
要将其移回,我只想将标准类分配回元素,该元素还将包含定位信息。
奇怪的是,除了重新定位之外,一切都会奏效。以下是相关代码:
var mytarget= document.getElementById(titlebarid);
var newclass=tabstyleclasses[titlebarid][ismaxedtab[titlebarid]];
mytarget.className= newclass ;
调试:
alert ("wanting to set : " + newclass ) ;
这会输出正确的值。(“adfieldtitlesm”)
alert ("my target is " +mytarget.id);
也可以。
alert ("new class is " + mytarget.className );
也给出正确的值。(“adfieldtitlesm”)
alert ("new position is " + mytarget.style.position );
给出“绝对”(之前由 JS 在移动 mytarget 时设置),应该是“固定的”
这是 CSS 类:
.adfieldtitlesm
{
position: fixed;
top: 200px;
left: 50px;
font-size: 50px;
background-color: #000000;
color: #ffffff;
}
为什么对象在其类设置后不会移动?
更新:链接
与此相关的部分是第一步rebuildtabs() 中的第270-297 行(主要是290-294),它可以工作,而minwidget() 中的第160-183 行为稍微混乱的代码道歉:)