forked from jasonujmaalvis/show-more
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.showmore.src.js
77 lines (61 loc) · 2.12 KB
/
jquery.showmore.src.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Show More jQuery Plugin
* Author: Jason Alvis
* Author Site: http://www.jasonalvis.com
* License: Free General Public License (GPL)
* Version: 1.0.4
* Date: 21.05.2013
*/
(function($) {
$.fn.showMore = function (options) {
// Default showmore
var defaults = {
speedDown : 300,
speedUp : 300,
height : '265px',
showText : 'Show',
hideText : 'Hide'
};
var options = $.extend(defaults, options);
return this.each(function() {
var $this = $(this),
$showMoreOrgHeight = $this.height();
if( $showMoreOrgHeight > parseInt(options.height) ){
// Insert showmore_content within the showmore div
$this.wrapInner('<div class="showmore_content" />');
// Set the height of the showmore_content
$this.find('.showmore_content').css('height', options.height)
// Append the showmore trigger within the showmore div
$this.append('<div class="showmore_trigger"><span class="more">' + options.showText + '</span><span class="less" style="display:none;">' + options.hideText + '</span></div>')
// Showmore going down
$this.find('.showmore_trigger').on('click', '.more', function (){
$(this).hide();
$(this).next().show();
$(this).parent().prev().animate({ height: $showMoreOrgHeight }, options.speedDown);
});
// Showmore going up
$this.find('.showmore_trigger').on('click', '.less', function(){
$(this).hide();
$(this).prev().show();
$(this).parent().prev().animate({ height: options.height }, options.speedUp);
});
}
});
};
})(jQuery);
/*
BASIC USAGE
$(document).ready(function() {
$('.showmore').showMore({
speedDown: 300,
speedUp: 300,
height: '165px',
showText: 'Show more',
hideText: 'Show less'
});
});
DEFAULT STYLES, ADD TO YOUR CSS
.showmore_content { position:relative; overflow:hidden; }
.showmore_trigger { width:100%; height:45px; line-height:45px; cursor:pointer; }
.showmore_trigger span { display:block; }
*/