J82
J82

Reputation: 8457

CSS slide does not slide, but just appears

I am trying to get div#project-wrapper to slide down when a.post-link is clicked at which point div.post-container gets the fadeOutDown class added through JS and fades in from the top. I'm having a couple problems:

1) div#project-wrapper, which gets the activated class added through JS, does not slide down when a.post-link is clicked. Instead it just appears.

2) The fadeOutDown class gets added to .post-container but the div doesn't do any of the CSS animations I wrote.

Can somebody please help me with this?

Fiddle: http://jsfiddle.net/eLooLb4c/2/

HTML

<div id="project-wrapper">
    <img id="loading-animation" src="http://i.imgur.com/5RMfW8P.gif">
    <div id="project-container">
        <div class="post-container fadeOutDown">
            <div id="project-left-content">
                <h1 class="entry-title">Test 1</h1>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
            </div>
            <div id="project-right-content"></div>
        </div><!-- #post-## -->
    </div>
</div>
<a class="post-link" href="#">post link</a>

CSS

#project-wrapper {
    background: #000;
    color: #fff;
    display: none;
    margin: 0 1%;
    position: relative;
    transform: translateY(-100%);
    -webkit-transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
    transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
}

#project-wrapper.activated {
    display: block;
    transform: translateY(0);
}

#project-wrapper #loading-animation {
    display: none;
    left: 0;
    position: absolute;
    top: 0;
}

#project-wrapper #project-container {
    overflow: hidden;
    padding: 40px;
}

@-webkit-keyframes fadeOutDown {
  0% {
    opacity: 0;
    -webkit-transform: translate(0, -10px);
            transform: translate(0, -10px);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
}

@keyframes fadeOutDown {
  0% {
    opacity: 0;
    margin-bottom: -10px;
    -webkit-transform: translate(0, -10px);
            transform: translate(0, -10px);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
}

.fadeOutDown {
  -webkit-animation-name: fadeOutDown;
          animation-name: fadeOutDown;
}

.fadeOutDown {
    -webkit-animation-name: fadeOutDown;
    animation-name: fadeOutDown;
}

#project-wrapper #project-container .post-container #project-left-content {
    float: left;
    margin-right: 4%;
    width: 40%;
}

#project-wrapper #project-container .post-container h1 {
    font-family: Helvetica,sans-serif;
    text-transform: uppercase;
    font-size: 40px;
    font-size: 3em;
    font-weight: bold;
    line-height: 1.1;
    margin-bottom: 0.8em;
}

#project-wrapper #project-container .post-container #project-right-content {
    background: #222;
    float: left;
    height: 350px;
    margin-top: 10px;
    width: 56%;
}

JS

$('.post-link').click(function(e) {
    e.preventDefault();

    function projectShow() {
        $('#project-wrapper').addClass('activated');
        $('.post-container').addClass('fadeOutDown');
    }

    if ($(window).scrollTop() != 0) {
        $('html, body').animate({
            scrollTop : 0
        },500, projectShow);
    } else {
        projectShow();
    }
});

Upvotes: 1

Views: 80

Answers (2)

Roumelis George
Roumelis George

Reputation: 6746

Since you are using jquery, you could save yourself some of the trouble and all this css and use something like this:

function projectShow() {
    $('#project-wrapper').slideDown();
    $('.post-container').hide().fadeIn();
}

Fiddle: updated example

Upvotes: 0

Akshay
Akshay

Reputation: 14348

This doesn't solve you first problem but the second problem is because you haven't given a time to your animation. See edit i figured out the first part too Fiddle

$('.post-link').click(function(e) {
    e.preventDefault();
    
    function projectShow() {
        $('#project-wrapper').addClass('activated' );
        $('.post-container').addClass('fadeOutDown');
    }
    
    if ($(window).scrollTop() != 0) {
        $('html, body').animate({
            scrollTop : 0
        },500, projectShow);
    } else {
        projectShow();
    }
});
#project-wrapper {
    background: #000;
    color: #fff;
    display: none;
    margin: 0 1%;
    position: relative;
    transform: translateY(-100%);
    -webkit-transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
    transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
}

#project-wrapper.activated {
    
    display: block;
    transform: translateY(0);
}

#project-wrapper #loading-animation {
    display: none;
    left: 0;
    position: absolute;
    top: 0;
}

#project-wrapper #project-container {
    overflow: hidden;
    padding: 40px;
}

@-webkit-keyframes fadeOutDown {
  0% {
    opacity: 0;
    -webkit-transform: translate(0, -10px);
            transform: translate(0, -10px);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
}

@keyframes fadeOutDown {
  0% {
    opacity: 0;
    margin-bottom: -10px;
    -webkit-transform: translate(0, -10px);
            transform: translate(0, -10px);
  }

  100% {
    opacity: 1;
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
}

.fadeOutDown {
  -webkit-animation-name: fadeOutDown 5s;
          animation-name: fadeOutDown;
}

.fadeOutDown {
    -webkit-animation: fadeOutDown 5s;
    animation-name: fadeOutDown;
}

#project-wrapper #project-container .post-container #project-left-content {
    float: left;
    margin-right: 4%;
    width: 40%;
}

#project-wrapper #project-container .post-container h1 {
    font-family: Helvetica,sans-serif;
    text-transform: uppercase;
    font-size: 40px;
    font-size: 3em;
    font-weight: bold;
    line-height: 1.1;
    margin-bottom: 0.8em;
}

#project-wrapper #project-container .post-container #project-right-content {
    background: #222;
    float: left;
    height: 350px;
    margin-top: 10px;
    width: 56%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div id="project-wrapper">
    <img id="loading-animation" src="http://i.imgur.com/5RMfW8P.gif">
	<div id="project-container">
        <div class="post-container">
    	    <div id="project-left-content">
	            <h1 class="entry-title">Test 1</h1>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
            </div>
            <div id="project-right-content"></div>
        </div><!-- #post-## -->
    </div>
</div>
<a class="post-link" href="#">post link</a>

Edit FIDDLE

I removed the display:block from here

#project-wrapper.activated {
transform: translateY(0);
}

and i edited the jquery like this

 function projectShow() {
    $('#project-wrapper').show(500);
    $('#project-wrapper').addClass('activated');

    $('.post-container').addClass('fadeOutDown');
}

$('.post-link').click(function (e) {
    e.preventDefault();

    function projectShow() {
        $('#project-wrapper').show(500);
        $('#project-wrapper').addClass('activated');

        $('.post-container').addClass('fadeOutDown');
    }

    if ($(window).scrollTop() != 0) {
        $('html, body').animate({
            scrollTop: 0
        }, 500, projectShow);
    } else {
        projectShow();
    }
});
#project-wrapper {
    background: #000;
    color: #fff;
    display: none;
    margin: 0 1%;
    position: relative;
    transform: translateY(-100%);
    -webkit-transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
    transition: all 0.5s cubic-bezier(0, 1, 0.5, 1);
}
#project-wrapper.activated {
    
    transform: translateY(0);
}
#project-wrapper #loading-animation {
    display: none;
    left: 0;
    position: absolute;
    top: 0;
}
#project-wrapper #project-container {
    overflow: hidden;
    padding: 40px;
}
@-webkit-keyframes fadeOutDown {
    0% {
        opacity: 0;
        -webkit-transform: translate(0, -10px);
        transform: translate(0, -10px);
    }
    100% {
        opacity: 1;
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
}
@keyframes fadeOutDown {
    0% {
        opacity: 0;
        margin-bottom: -10px;
        -webkit-transform: translate(0, -10px);
        transform: translate(0, -10px);
    }
    100% {
        opacity: 1;
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
}
.fadeOutDown {
    -webkit-animation: fadeOutDown 5s;
    animation: fadeOutDown 5s;
}
#project-wrapper #project-container .post-container #project-left-content {
    float: left;
    margin-right: 4%;
    width: 40%;
}
#project-wrapper #project-container .post-container h1 {
    font-family: Helvetica, sans-serif;
    text-transform: uppercase;
    font-size: 40px;
    font-size: 3em;
    font-weight: bold;
    line-height: 1.1;
    margin-bottom: 0.8em;
}
#project-wrapper #project-container .post-container #project-right-content {
    background: #222;
    float: left;
    height: 350px;
    margin-top: 10px;
    width: 56%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="project-wrapper">
    <img id="loading-animation" src="http://i.imgur.com/5RMfW8P.gif">
    <div id="project-container">
        <div class="post-container">
            <div id="project-left-content">
                 <h1 class="entry-title">Test 1</h1>

                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
            </div>
            <div id="project-right-content"></div>
        </div>
        <!-- #post-## -->
    </div>
</div>
<a class="post-link" href="#">post link</a>

Upvotes: 1

Related Questions