0
我有一个简单的问题,我不知道如何处理它,因为我学习JavaScript触发CSS过渡锚定于JavaScript
我想要做的就是一个链接导航锚在CSS上淡入/淡出过渡。为此,我必须使用JavaScript获取当前页面ID和锚点href,并触发CSS效果。
这是我走到这一步:
$('.btn').click(function(e) {
e.preventDefault();
var next = $(this).attr('href');
$(this).parent().addClass('fadeout', function() {
setTimeout(function() {
$(this).parent().css('display', 'none');
}, 1000);
$('#' + next).css('display', 'block');
$('#' + next).addClass('fadein');
});
});
.fadeout {
opacity: 0;
transition: all 1000ms ease;
}
.fadein {
opacity: 1;
transition: all 1000ms ease;
}
#page2,
#page3 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="page1">
Page 1 Content
<br>
<a href="page2" class="btn">Show Page 2 and hide this page</a>
<br>
<a href="page3" class="btn">Show Page 3 and hide this page</a>
</div>
<div id="page2">
Page 2 Content
<br>
<a href="page1" class="btn">Show Page 1 and hide this page</a>
<br>
<a href="page3" class="btn">Show Page 3 and hide this page</a>
</div>
<div id="page3">
Page 3 Content
<br>
<a href="page1" class="btn">Show Page 1 and hide this page</a>
<br>
<a href="page2" class="btn">Show Page 2 and hide this page</a>
</div>
预先感谢您帮助我学习
能否请您解释一下什么是你的问题? @Ermac –
看到代码段中的错误,我可以淡出我的内容,但我无法加载新的:( – Ermac