-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.readMore.js
92 lines (57 loc) · 2.57 KB
/
jquery.readMore.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
readMore 1.1 - jQuery plugin
written by O! Interactive, Acuna
http://ointeractive.ru
Copyright (c) 2015, 2020 O! Interactive, Acuna (http://ointeractive.ru)
Dual licensed under the MIT (MIT-LICENSE.txt)
and GPL (GPL-LICENSE.txt) licenses.
Built for jQuery library
http://jquery.com
Dependencies: none
1.0 24.02.2015
Первый приватный релиз
1.1 14.08.2020
Совместимость с Bootstrap
*/
(function ($) {
$.fn.readMore = function (options) {
options = $.extend ({
'slideHeight': 200,
'langMore': 'Читать далее...',
'langLess': 'Свернуть',
'speed': 500,
'maxElem': 100,
'tab': 15,
'scrollTop': true,
}, options);
$(this).each (function () {
var rand = Math.floor (Math.random () * options['maxElem']);
$(this).wrapInner ('<div class="read-more-wrapper elem-' + rand + '"></div>');
var wrapper = $('.elem-' + rand);
var defHeight = wrapper.height ();
if (defHeight >= options['slideHeight']) {
wrapper.after ('<div class="read-more-link link-' + rand + '"></div>');
var readMore = $('.link-' + rand);
wrapper.append ('<div class="read-more-gradient gradient-' + rand + '"></div>');
var gradient = $('.gradient-' + rand);
wrapper.css ({ 'height':options['slideHeight'] + 'px', 'overflow': 'hidden' });
readMore.append ('<a href="#">' + options['langMore'] + '</a>');
readMore.children ('a').click (function () {
var curHeight = wrapper.height ();
if (curHeight == options['slideHeight']) {
wrapper.animate ({ 'height':defHeight }, 'normal');
$(this).text (options['langLess']).addClass ('read-more-close');
gradient.fadeOut ();
} else {
wrapper.animate ({ height:options['slideHeight'] }, options['speed']);
$(this).text (options['langMore']);
gradient.fadeIn ();
}
if (options['scrollTop'])
$('body,html').animate ({ 'scrollTop':((wrapper.position ().top + options['slideHeight']) - options['tab']) }, options['speed']);
return false;
});
}
});
};
})($);