This time I will share jQuery Plugin and tutorial about Hide/Reveal Long Text On Demand – jQuery MoreContent, hope it will help you in programming stack.
The MoreContent jQuery plugin automatically cuts off long text content within a container and reveals/hides them with a smooth toggle animation when needed.
Features:
- Hides long content when exceeding the max height.
- Fully responsive and works perfectly on window resize.
- Custom Read More and Read Less buttons.
- Custom trigger event. Default: ‘Click’.
- Shadow effect on exceeded content.
- Custom easing functions.
- Useful API methods.
How to use it:
1. Insert both jQuery JavaScript library and the MoreContent plugin into the document.
1 |
< script src = "/path/to/jquery.min.js" ></ script > |
2 |
< script src = "/path/to/jquery.morecontent.js" ></ script > |
2. Call the function on the text container and done. By default the plugin will automatically hide exceeded text when the container is higher than 175px.
1 |
$( '.example' ).moreContent(); |
3. Set the maximum height to trigger the Hide behavior. Default: ‘175’.
1 |
$( '.example' ).moreContent({ |
4. Customize the trigger event to toggle the full content. Default: ‘Click’.
1 |
$( '.example' ).moreContent({ |
5. Apply a shadow effect to the exceeded content. Default: ‘false’.
1 |
$( '.example' ).moreContent({ |
6. Apply an easing effect to the toggle animation. You might need a 3rd easing library for extra easing functions. E.g. jQuery UI and jQuery easing plugin.
1 |
$( '.example' ).moreContent({ |
2 |
easing: 'easeOutBounce' |
7. Customize the text for the read more and read less buttons.
1 |
$( '.example' ).moreContent({ |
2 |
textClose: 'Show More' , |
8. More configuration options.
01 |
$( '.example' ).moreContent({ |
05 |
content: '<div class="mrc-content"></div>' , |
06 |
contentWrap: '<div class="mrc-content-wrap"></div>' , |
07 |
btn: '<button class="mrc-btn" type="button"></button>' , |
08 |
btnWrap: '<div class="mrc-btn-wrap"></div>' , |
09 |
controls: '<div class="mrc-controls"></div>' , |
10 |
shadow: '<div class="mrc-shadow"></div>' , |
9. API methods available.
02 |
$( '.example' ).moreContent( 'reinit' ); |
05 |
$( '.example' ).moreContent( 'close' ); |
08 |
$( '.example' ).moreContent( 'Open' ); |
11 |
$( '.example' ).moreContent( 'toggle' ); |
14 |
$( '.example' ).moreContent( 'drop' ); |
17 |
$( '.example' ).moreContent( 'destroy' ); |
10. Event handlers.
01 |
instance.on( 'beforeInitSwitch.mrc' , function (e, inst, sets) { |
13 |
instance.on( 'change.mrc' , function (e, inst, sets) { |
39 |
instance.on( 'beforeOpen.mrc' , function (e, inst, sets, content, height) { |
51 |
instance.on( 'beforeClose.mrc' , function (e, inst, sets, content, height) { |