-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextWall.js
66 lines (53 loc) · 1.81 KB
/
TextWall.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
(function($) {
$.TextWall = function(el, options) {
var self = this;
self.$el = $(el);
self.el = el;
self.$el.data("TextWall", self);
self.init = function() {
self.options = $.extend({}, $.TextWall.defaults, options);
self.generator(self.options);
};
self.generator = function(options) {
var arr = options.texts;
while (arr.length > 0) {
var index = getRandInt(0, arr.length - 1);
console.log('index', arr.length);
var div = $('<div class="text"></div>').text(arr[index]);
div.css('font-size', getRandNum(
options.minFontSize, options.maxFontSize) + 'px');
// div.css('left', getRandNum(0, self.$el.width()));
// div.css('top', getRandNum(0, self.$el.height()));
div.css('margin-left', getRandNum(50, 100));
div.css('margin-right', getRandNum(50, 100));
div.css('margin-top', getRandNum(-20, 0));
div.css('margin-bottom', getRandNum(10, 25));
div.css('transform', 'rotate(' + getRandNum(-10, 10) + 'deg)');
self.$el.append(div);
arr.splice(index, 1);
}
// options.texts.forEach(function(text) {
// });
}
self.init();
};
$.TextWall.defaults = {
minFontSize: 18,
maxFontSize: 25,
gap: 0.3,
texts: [],
};
$.fn.textWall = function(options) {
return this.each(function() {
(new $.TextWall(this, options));
});
};
$.fn.test = function(str) {
};
function getRandNum(min, max) {
return Math.random() * (max - min) + min;
}
function getRandInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
})(jQuery);