작업 : 클릭하면 전환 페이드 인으로 콘텐츠가 보이거나 숨겨집니다.여러 조건문에 대해 jQuery에서 페이드 인을 추가하십시오.
문제 나는이 fadein // fadeout 전환을 배치 할 위치를 추측하고 점검하고 있습니다. 또한 4 개의 조건문을 사용하기 때문에 코드가 너무 비효율적 인 것처럼 느껴집니다. 스택을 사용하면이 스크립트의 전반적인 논리를 개선 할 수있는 솔루션을 만들 수있게되어 꽤 전환 할 수 있습니다. c?
jQuery를 스크립트
$(document).ready(function() {
//attach a single click listener on li elements
$('li.navCenter').on('click', function() {
// get the id of the clicked li
var id = $(this).attr('id');
// match current id with string check then apply filter
if (id == 'printInteract') {
//reset all the boxes for muliple clicks
$(".box").find('.video, .print, .web').closest('.box').show();
$(".box").find('.web, .video').closest('.box').hide();
$(".box").find('.print').show();
}
if (id == 'webInteract') {
$(".box").find('.video, .print, .web').closest('.box').show();
$(".box").find('.print, .video').closest('.box').hide();
$(".box").find('.web').show();
}
if (id == 'videoInteract') {
$(".box").find('.video, .print, .web').closest('.box').show();
$(".box").find('.print, .web').closest('.box').hide()
$(".box").find('.video').show();
}
if (id == 'allInteract') {
$(".box").find('.video, .print, .web').closest('.box').show();
}
});
HTML 선정
<nav>
<ul class="navSpaces">
<li id="allInteract" class="navCenter">
<a id="activeAll" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>all</h3></div></a>
</li>
<li id="printInteract" class="navCenter">
<a id="activePrint" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/print.gif" /><h3>print</h3></div></a>
</li>
<li id="videoInteract" class="navCenter">
<a id="activeVideo" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/video.gif" /><h3>video</h3></div></a>
</li>
<li id="webInteract" class="navCenter">
<a id="activeWeb" class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/web.gif" /><h3>web</h3></div></a>
</li>
</ul>
BOX HTML
<div class="box">
<h1 title="Light me up"></h1>
<div class="innerbox">
<figure>
<img src="" />
</figure>
<ul class="categorySelect">
<li class="print"></li>
<li class="video"></li>
<li class="web"></li>
</ul>
</div>
PS. 초보자 질문
젠장, 너는 너무 가까이있어 프리츠 onclick에서 kinna하지만 가까운 당신은 내가 코드를 업데이 트거야? btw 나는 당신의 결정을 위해 모든 편집 타이를 보았습니다 –
http://designobvio.us/ie/# 코드를 업데이트했습니다. 모든 것을 이해하기 위해 노력하고 있습니다! 하지만 할 수 있기 전에 편집 할 거라고 확신합니다. –
@MatthewHarwood -'.box'와'.video, .print, .web' 조각에 대해 HTML을 포함하지 않았으므로, 숨기거나 표시하는 가장 효율적인 방법은 무엇인지, 그리고 우리는 가능한 솔루션을 테스트 할 수있는 방법이 있습니다. 나는 다시 편집했다. 나는 당신이 단지 원래 코드가 때때로하고있는'.box' 컨테이너를 숨기거나 보여주기를 원한다고 가정하고 있습니다. – jfriend00