【发布时间】:2018-04-24 03:14:32
【问题描述】:
如果这是一个重复的问题,我真的很抱歉。
我想设置 #menudd.show 的最大高度来满足我的过渡。我想在 javascript 中执行此操作,以便更精确地指定值。
这是我得到的,但由于某种原因它无法正常工作......
HTML:
<div id="menudd">
<a href="index.html">Home</a>
<a href="aboutme.html">About Me</a>
<a href="shotterm.html">Short-Term</a>
<a href="middleterm.html">Middle-Term</a>
<a href="longterm.html">Long-Term</a>
</div>
CSS:
#menudd {
position: fixed;
overflow: hidden;
max-height: 0px;
opacity: 0;
width: 200px;
border-radius: 10px;
box-shadow: 0 0 35px 15px black;
transition: all 1s ease;
}
#menudd.show {
opacity: 1;
}
JavaScript:
$("#menudd." + show).get(0).style.maxHeight = document.getElementById("menudd").getElementsByTagName("A")[0].offsetHeight * document.getElementById("menudd").getElementsByTagName("A").length + "px";
这会在控制台中输出“显示未定义”。
如果我使用 $("#menudd.show").get(0).style.maxHeight 它会在控制台中输出“无法读取未定义的属性 'style'”。
如果我使用 $("#menudd.show").style.maxHeight 它会在控制台中输出“无法读取未定义的属性 'maxHeight'”。
非常感谢任何帮助!祝你有美好的一天。 :)
【问题讨论】:
-
你想达到什么目的?
-
$("#menudd." + show)不应该只是$("#menudd.show")吗?我不明白变量的用法。 -
控制台输出是什么?如果有,请将其添加到问题中。
-
我已经把这个添加到帖子中了。
标签: javascript jquery html css styles