1

http://jsfiddle.net/cD4Gr/4/

Le Code:

$j(document).bind('click', function() { 
    $j("#test").css({ bottom:0px })
    });

Looking in the inspector, even when the element is at the top of the page, it still says it's bottom value is 0.

Maybe I need to play the animation in reverse somehow? or play a different animation? (Using Bottom %, rather than top %)

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

2 Answers2

3

As you were thinking you can make a second keyframe block to reset it back to the bottom:

@-webkit-keyframes reset_to_bottom {
    0%, 100% {
        top: auto;
        bottom: 0;
        z-index: 1000000;
        opacity: 0.5;
    }
}

then have your jQuery change the animation name:

$j("#test").css({
    '-webkit-animation-name': 'reset_to_bottom'
});

jsfiddle

When using -webkit-animation-fill-mode: forwards; forwards will maintain the last keyframe styles, so top:0% is still set which is why bottom:0 was having no effect


for fun...switch between animation's each click

jsfiddle

$j(document).bind('click', function() {
    if ($j("#test").css('-webkit-animation-name') == "slide_to_top") {
        $j("#test").css({'-webkit-animation-name': 'reset_to_bottom'});
    } else {
        $j("#test").css({'-webkit-animation-name': 'slide_to_top'});
    }
});
MikeM
  • 27,227
  • 4
  • 64
  • 80
0

If I'm understanding the situation correctly, I think these modifications should fix your problem:

CSS:

#test {
  ...
  //bottom: 0px; //Remove this line
  top:100%;      //Replace with this
  ...
}

JavaScript:

//$j("#test").css({ bottom:0px })
$j("#test").css({ top:0 })

On a side note, I prefer using the jQuery animate() function rather than CSS for animations, mainly because it already has support for all major browsers. That way, I don't have to worry about including multiple CSS styles for different browsers.

RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55