[英]Changing a dom element's position after load without jquery
hey i have some code that sets an elements style.width, height, and position but its not working and I assumed it was because it was'nt in the head, but I want to change the css on like a mouseclick event so tabs will slide out and stuff but I'd rather not use jquery is there a way to do this? 嘿,我有一些代码设置一个元素style.width,height和position,但是它不起作用,我认为这是因为它不在头上,但是我想像mouseclick事件一样更改css,因此制表符会滑出来的东西,但我宁愿不使用jQuery,有没有办法做到这一点?
edit: ok so Iv got the width and height problem solved exact it doesnt seem to respond when I try and position it 编辑:好的,所以IV解决了宽度和高度问题,当我尝试放置它时似乎没有响应
here's my code 这是我的代码
for (i=1; i<=tab_array.length-1; i++)
{
if (i==3)
{
document.getElementById("_"+i).style.cssText='height:'+Math.floor(p(100,gheight))+'px;'+
'width:' +Math.floor(p(80,gwidth ))+'px;'+
'background:black;'+
'postion:absolute;'+
'left:'+Math.floor(p(tab_array.across,gwidth)-gwidth)+'px;'
;
}
else
{
document.getElementById("_"+i).style.cssText='height:'+Math.floor(p(80,gheight))+'px;'+
'width:' +Math.floor(p(80,gwidth ))+'px;';
}
}
Try something like: 尝试类似:
function E(e){
return document.getElementById(e);
}
function changeSize(id, height, width, interval){
var es = E(id).style, h = parseInt(height), w = parseInt(width), f = Math.floor(h/w), n = parseInt(interval), i = 0;
var sit = setInterval(function(){
i++; es.cssText = 'height:'+i*f+'px; width:'+i+'px;';
if(i === w){
es.cssText = 'height:'+h+'px; width:'+w+'px;'; clearInterval(sit);
}
}, n);
}
changeSize('box', 100, 50, 20);
For the working example, visit http://jsfiddle.net/PHPglue/X6TMv/ . 有关工作示例,请访问http://jsfiddle.net/PHPglue/X6TMv/ 。 I did not add easing, which jQuery handles quite effectively though. 我没有添加缓动,尽管jQuery相当有效。 I made the code to take Strings or Numbers from height on. 我编写了从高处开始接受字符串或数字的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.