我不能爲我的生活找出爲什麼建立這個地鐵網格後http://codepen.io/anon/pen/yoxzp,如果它已經被展開,我不能再次點擊同一個正方形。任何人都可以很好地幫助我嗎?動畫後我不能點擊元素(我猜不出來)
var tile = $('.metro-grid > * ');
tile.on('click', function() {
tile.not($(this))
.addClass('fade-out')
.addClass('hidden');
$(this).removeClass('hidden')
.addClass('flip')
.addClass('exploded-tile');
tile.not($(this))
.addClass('hidden');
$(this).children()
.data('function', 'exploded_content')
.removeClass('hidden');
tile.click(revert);
});
function revert() {
tile.removeClass('hidden')
.removeClass('flip')
.removeClass('exploded-tile')
.removeClass('fade-out');
$('[data-function="exploded_content"]').removeClass('shown').addClass('hidden')
}
<header>Click to expand/Click again to close.. But try clicking the same tile after it has been restored to its default state</header>
<div id="main" role="main">
<article class="metro-grid animated">
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become <a href="javascript:alert('!')">dfdfefef</a>
<img src="http://placehold.it/1550x1550/ffffff" alt="" />
</div>
</section>
<section class="large-tile">
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section class="medium-tile">
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section class="large-tile">
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section class="medium-tile">
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
<section>
<h1>Tile title</h1>
<h2>Tile subtitle</h2>
<div class="hidden" data-function="exploded_content">
This is additional stuff that will become hidden
</div>
</section>
</article>
<!-- <button onclick="revert()" style="position: fixed; top: 0; z-index: 10;">Revert</button>-->
</div>
<footer>
</footer>
在**問題中顯示標記**,而不僅僅是鏈接。 –
爲什麼要將'hidden'添加到不是'$(this)'的元素兩次? (注意:沒有理由做'.not($(this))','.not(this)'就足夠了。 –
在調用'tile.click(revert);'之前,我會將原來的偵聽器防止這兩個處理程序觸發:'$(this).off('click'); $(this).click(revert);''你可以讓'revert'函數重新將偵聽器添加到那個元素。 – nbrooks