Last active
November 21, 2018 22:27
-
-
Save j0hj0h/27d996d5ceeb8e6f1890833795c00c4a to your computer and use it in GitHub Desktop.
Minimal showMore JS-Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-show-more> | |
<div data-show-more-content> | |
... | |
</div> | |
<button type="button" data-show-more-toggle> | |
<span class="more">Show more</span> | |
<span class="less">Show less</span> | |
</button> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var showMore = (function(){ | |
function init() { | |
$('[data-show-more]').each(function(){ | |
init_one(this); | |
}); | |
} | |
function init_one(one) { | |
$one = $(one); | |
$toggle = $one.find('[data-show-more-toggle]'); | |
$toggle.click(function(){ | |
$one.toggleClass('active'); | |
}); | |
} | |
return { | |
init : init | |
}; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[data-show-more] { | |
[data-show-more-content] { | |
display: none; | |
} | |
[data-show-more-toggle] .less { | |
display: none; | |
} | |
&.active { | |
[data-show-more-content] { | |
display: block; | |
} | |
[data-show-more-toggle] { | |
.more { | |
display: none; | |
} | |
.less { | |
display: inline; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment