Skip to content

Instantly share code, notes, and snippets.

@j0hj0h
Last active November 21, 2018 22:27
Show Gist options
  • Save j0hj0h/27d996d5ceeb8e6f1890833795c00c4a to your computer and use it in GitHub Desktop.
Save j0hj0h/27d996d5ceeb8e6f1890833795c00c4a to your computer and use it in GitHub Desktop.
Minimal showMore JS-Module
<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>
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
};
})();
[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