1

This is a really weird issue! If any brains out their could explain I would appreciate it!

I am trying to get a CSS transition to run when a page loads using the following code (JS Bin)

HTML

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <meta charset="utf-8">
    <title>JS Bin</title>
</head>
<body>
    <div id="my-message">My message</div>
</body>
</html>

CSS

#my-message {
    overflow-y: hidden;
    background: yellow;
}

.my-transition {
    transition: height 4s;
}

JavaScript

$( document ).ready( function() {

    var $myMessage = $( '#my-message' );

    var height = $myMessage.height();

    $myMessage.height( 0 );

    $myMessage.addClass( 'my-transition' );

    $myMessage.css( 'height', height );

} );

The transition works as expected in Safari however in Chrome it just shows instantly (no transition).

The weird thing is if you change the last command in the JavaScript from $myMessage.css( 'height', height ); to $myMessage.heigh( height ); it works in both!

WHY!?!?!?!?

0

1 Answer 1

1

I think it is because of the behaviour of chrome, I added the setTimeout on your js and it worked

setTimeout(function(){  $myMessage.css( 'height', height );},1);

Updated jsbin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.