1)我想改变一个div的CSS属性,以便它在点击时像模态一样弹出。这个CSS代码改变div的大小和位置,我需要什么:CSS转换JS功能不能正常工作
#slot1{
position: absolute;
top: 10px;
left: 20%;
height: 600px;
width: 60%;
margin: auto;
}
2)为此,我做了一个JS的功能,可以让我改变元素的CSS上面的那些:
function boxPop(id, cssValue, cssValue, cssValue, cssValue, cssValue)
{
document.getElementById(id).style.position = cssValue;
document.getElementById(id).style.top = cssValue;
document.getElementById(id).style.left = cssValue;
document.getElementById(id).style.height = cssValue;
document.getElementById(id).style.width = cssValue;
document.getElementById(id).style.margin = cssValue;
}
3)I加入此具有所需参数的HTML元素:
<div class="slot_content" id="slot1" onclick="boxPop('slot1', 'absolute',
'10px', '20%', '600px', '60%', 'auto')">
</div>
所有这一切的结果是,它的变化的大小和位置,而不是在我只贴上相同的值它的方式到CSS(这是我想要的)。有谁知道为什么CSS值没有被这个函数正确分配?
你所写的功能发生在6个参数,但是当你调用它,你在7 – blackandorangecat
传给你有5个参数调用cssValue ...你怎么能指望的功能“知道”哪个是哪个? –