"JS Truncating Multiple Line Text (crop, clampin)"
Bootstrap 3.3.0 Snippet by iwebdesigner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<h2>JS Truncating Multiple Line Text <small>(crop, clampin)</small></h2>
</div>
<div class="row">
<div class="col-lg-3">
<div class="thumbnail">
<img src="http://placehold.it/250x150" alt="Image">
<div class="caption">
<h3 class="crop-text">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</h3>
</div>
</div>
</div>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
var size = 20,
cropContent = $('.crop-text'),
cropText = cropContent.text();
if (cropText.length > size) {
cropContent.text(cropText.slice(0, size) + ' ...');
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: