Responsive Jquery Read More Feature Without Plugin: Hi Friends, Today i will tell you about how to create a responsive read more feature of jquery without any plugin. As we know for creating a read more feature we have to add a jquery plugin but it increase our page speed. If you use less code of jquery, your page load faster.
Today i am creating a read more feature in the paragraph, firstly only few lines of paragraph are showing. After clicking on read more button your paragraph loads completely.
See the live demo and download the code from below:
For creating a responsive jquery read more feature, you can follow some steps. These Steps are
Open your webpage in any code editor.
Paste the below code to make the functionality of read more button on click.
I have created some div in which content and button is there.
<div class="cont-box"> <div class="box"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> <div class="btn"> Read More </div> </div> |
<div class="cont-box"> <div class="box"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> <div class="btn"> Read More </div> </div>
I am giving some styling of my read more button and content using css.
.cont-box { background: #1E90FF; color: #fff; padding: 30px; width: 50%; border:2px solid #000; margin: 20px auto; position: relative; font-size: 20px; } .cont-box .btn { color: #fff; padding: 5px 8px; background-color: #ff0000; position: absolute; right: 1px; bottom: 1px; margin-top: 5px; } .cont-box .box { height: 50px; overflow: hidden; } .cont-box .box.active { height: 100%; } |
.cont-box { background: #1E90FF; color: #fff; padding: 30px; width: 50%; border:2px solid #000; margin: 20px auto; position: relative; font-size: 20px; } .cont-box .btn { color: #fff; padding: 5px 8px; background-color: #ff0000; position: absolute; right: 1px; bottom: 1px; margin-top: 5px; } .cont-box .box { height: 50px; overflow: hidden; } .cont-box .box.active { height: 100%; }
Jquery code is giving a functionality of read more to open and close on just click on single button.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(".btn").click(function(){ $('.box').toggleClass("active"); }); </script> |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(".btn").click(function(){ $('.box').toggleClass("active"); }); </script>
After pasting all the codes, check your webpage in the browser.
For any problem you can see the live demo and download the code from below.
Read About Other Interesting Things below.
I hope you will like Responsive Jquery Read More Feature Without Plugin. If You found it useful please subscribe my blog.
Categories: Website Design
Love this simple implementation of the read more. How do I have the button to display show less when the full text is shown?
HI Mena,
You have to write more code for this and specify more and less text in some variable and toggle the button when any user event is occurring