This time I will share jQuery Plugin and tutorial about Basic Read More / Read Less Plugin With jQuery – shorten.js, hope it will help you in programming stack.
shorten.js is a small jQuery plugin which limits the characters length in your text and creates read more / read less to expand & collapse the text block. Typically used for shortening descriptions and excerpts of your blog post.
How to use it:
1. Insert the shorten plugin’s stylesheet and JavaScript into your jQuery page.
1 |
< link rel = "stylesheet" href = "shorten.css" > |
2 |
< script src = "//code.jquery.com/jquery.min.js" ></ script > |
3 |
< script src = "jquery-shorten.js" ></ script > |
2. Just call the function on the target text container and the plugin will do the rest. By default the character limit is 100 characters:
2 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas fringilla pretium nisi, non dapibus diam rhoncus sed. Vivamus vel nunc venenatis, rutrum felis at, euismod ligula. Aenean vulputate luctus ultricies. Nulla imperdiet ac arcu sit amet vestibulum. Nunc auctor cursus lectus, vel cursus dolor fringilla eget. Vestibulum porta nunc vitae urna tempor, eget aliquam purus hendrerit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec aliquet eu purus accumsan dignissim. Nulla nisi nulla, bibendum ut rhoncus nec, eleifend quis arcu. |
3. Override the default character limit.
4. Specify the text for the read more / read less links.
5. Specify the ellipses character.
6. API methods.
02 |
( '.desc' ).shorten( 'text' ); |
05 |
( '.desc' ).shorten( 'expand' ); |
09 |
( '.desc' ).shorten( 'collapse' ); |
12 |
('.desc ').shorten(' update ', ' new content '); |
14 |
// Destroy the shorten instance. |
15 |
(' .desc ').shorten(' destroy'); |
7. Events available.
01 |
( '.desc' ).on( 'shorten::ready' , function (e) { |
05 |
( '.desc' ).on( 'shorten::expand' , function (e) { |
09 |
( '.desc' ).on( 'shorten::collapse' , function (e) { |
13 |
( '.desc' ).on( 'shorten::update' , function (e) { |
17 |
( '.desc' ).on( 'shorten::destroy' , function (e) { |
This awesome jQuery plugin is developed by amazingSurge. For more Advanced Usages, please check the demo page or visit the official website.