Animate Height Bottom to Top Instead of Top to Bottom
How can I achieve height animation in reverse?
Instead of the typical animation starting from the top and working its way down, how can I have it start the animation from the bottom of the element and work its way up towards the top of the element?
The event is triggered by a#link-1
, the animation takes place in div#line-1
.
This is my code: It doesn't appear to be working. :-/
HTML
<div id="pageContainer">
<div id="line-1"></div>
<a id="link-1" title="" href="#">Link 1</a>
</div><!-- end #pageContainer -->
CSS
#pageContainer{
position: relative;
margin: 0px 0px 200px 0px;
min-height: 748px;
height: 748px;
background: url('../img/sprite.png') bottom center no-repeat;
}
a#link-1{
position: absolute;
top: 686px;
left: 36px;
text-align: center;
display: block;
width: 76px;
height: 24px;
line-height: 24px;
z-index: 20;
}
div#line-1{
position: absolute;
top: 4px;
left: 30px;
width: 340px;
height: 687px;
background: url('../img/sprite.png') 0px 0px no-repeat;
}
JS
// Initially hide
$("div#line-1").hide();
// Activate Line 1
$('a#link-1').click(function() {
$('div#line-1').animate({
opacity: 0.25,
height: 'toggle'
}, 5000, function() {
// Animation comp开发者_如何学运维lete.
});
});
You div
and your a tags have the same ID. They must have unique IDs.
$('a#line-1').click(function() {
$('div#line-1').animate({
needs to be something like:
$('a#line-1').click(function() {
$('div#unique_id').animate({
Example Fix
position: absolute;
bottom: 0px;
animate bottom + 1.
You can also use negative values for top
or margin-top
to move upwards.
Animate as you would for top-to-bottom, but add element.scrollTop = 99999;
This will ensure that the bottom of the content is visible (unless for some reason it's 100,000 pixels tall) and the effect will be bottom-to-top animation.
精彩评论