-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadMoreFade.js
More file actions
49 lines (40 loc) · 1.75 KB
/
Copy pathreadMoreFade.js
File metadata and controls
49 lines (40 loc) · 1.75 KB
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
(function ( $ ) {
$.fn.readMoreFade = function(options) {
var settings = $.extend({
backgroundColor: "white",
buttonClass: "button"
}, options );
this.css( "height", 160 );
this.css( "overflow", "hidden" );
this.css( "position", "relative" );
this.append('<p class="readMoreFade"><a href="#" class="' + settings.buttonClass + '">Read More</a></p>')
var readMoreButton = this.find('.readMoreFade');
var backgroundString = settings.backgroundColor ? settings.backgroundColor : this.css('background-color');
readMoreButton.css('background-image', '-webkit-gradient(linear,left top,left bottom,color-stop(0, rgba(255,0,0,0)),color-stop(1, '+backgroundString+'))');
readMoreButton.click(function(){
totalHeight = 0
$el = $(this);
$p = $el;
$up = $p.parent();
$ps = $up.find("p:not('.readMoreFade')");
// measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
$ps.each(function() {
totalHeight += $(this).outerHeight();
});
$up
.css({
// Set height to prevent instant jumpdown when max height is removed
// "height": $up.height(),
"max-height": 9999
})
.animate({
"height": totalHeight
});
// fade out read-more
$p.fadeOut();
// prevent jump-down
return false;
})
return this;
};
}( jQuery ));