我想在div#project-wrapper
点击a.post-link
时向下滑动div.post-container
,fadeOutDown
通过JS添加div#project-wrapper
类并从顶部淡入。我有几个问题:
1)activated
,获取通过JS添加的a.post-link
类,在单击fadeOutDown
时不会滑动。而只是出现。
2).post-container
类被添加到<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>
但是div没有做我写的任何CSS动画。
有人可以帮帮我吗?
小提琴:http://jsfiddle.net/eLooLb4c/2/
HTML
#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%;
}
CSS
$('.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();
}
});
JS
{{1}}
答案 0 :(得分:1)
这不能解决您的第一个问题,但第二个问题是因为您没有给动画留出时间。请参阅编辑,我也想出了第一部分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>
修改 FIDDLE
我从这里删除了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>
答案 1 :(得分:0)
因为你正在使用jquery,你可以省去一些麻烦和所有这些css并使用这样的东西:
function projectShow() {
$('#project-wrapper').slideDown();
$('.post-container').hide().fadeIn();
}
小提琴:updated example