我试图让div#project-wrapper
在点击a.post-link
时向下滑动,此时div.post-container
将通过JS添加fadeOutDown
类,并从顶部逐渐消失。我有几个问题:
1) div#project-wrapper
获取通过JS添加的activated
类,在单击a.post-link
时不向下滑动。相反,它只是出现了。
2) fadeOutDown
类被添加到.post-container
中,但是div不执行我编写的任何CSS动画。
有人能帮帮我吗?
小提琴:http://jsfiddle.net/eLooLb4c/2/
<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();
}
});
发布于 2015-01-10 12:06:50
这不能解决你的第一个问题,但第二个问题是因为你还没有给你的动画时间。参见编辑--我知道第一部分太小提琴了
$('.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>
编辑 小提琴
我把display:block
从这里移走了
#project-wrapper.activated {
transform: translateY(0);
}
我像这样编辑jquery
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>
发布于 2015-01-10 13:40:08
由于您使用的是jquery,所以您可以省去一些麻烦和所有这些css,并使用如下所示:
function projectShow() {
$('#project-wrapper').slideDown();
$('.post-container').hide().fadeIn();
}
小提琴:更新的例子
https://stackoverflow.com/questions/27876002
复制相似问题