【发布时间】:2016-11-18 03:16:10
【问题描述】:
我想从底部而不是像我一样从顶部打开带有动画的文本:
function showHide(shID) {
if (document.getElementById(shID)) {
if (document.getElementById(shID+'-show').style.display != 'none') {
document.getElementById(shID+'-show').style.display = 'none';
document.getElementById(shID+'-hide').style.display = 'inline';
document.getElementById(shID).style.height = '100px';
}
else {
document.getElementById(shID+'-show').style.display = 'inline';
document.getElementById(shID+'-hide').style.display = 'none';
document.getElementById(shID).style.height = '0px';
}
}
}
#example {
background: red;
height: 0px;
overflow: hidden;
transition: height 2s;
-moz-transition: height 2s; /* Firefox 4 */
-webkit-transition: height 2s; /* Safari and Chrome */
-o-transition: height 2s; /* Opera */
}
a.showLink, a.hideLink {
text-decoration: none;
background: transparent url('down.gif') no-repeat left;
}
a.hideLink {
background: transparent url('up.gif') no-repeat left;
}
Here is some text.
<div class="readmore">
<a href="#" id="example-show" class="showLink" onclick="showHide('example');return false;">Read more</a>
<div id="example" class="more">
<div class="text">
Here is some more text: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum vitae urna nulla.
Vivamus a purus mi. In hac habitasse platea dictumst. In ac tempor quam.
Vestibulum eleifend vehicula ligula, et cursus nisl gravida sit amet.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
<p>
<a href="#" id="example-hide" class="hideLink" onclick="showHide('example');return false;">Hide</a>
</p>
</div>
</div>
jsFiddle
【问题讨论】:
-
你说的“自下而上”是什么意思?你想先看内容的最后一部分吗?
-
是的,对不起!我希望看到基本上相反的效果,这样当我展开文本时,它会从底部(内容的最后一部分)向顶部打开
-
不知道怎么做:(
-
this 会做你想做的事,但动画不同。
标签: javascript jquery html css