-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
146 lines (144 loc) · 6.1 KB
/
script.js
File metadata and controls
146 lines (144 loc) · 6.1 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
$(document).ready(function () {
/*
* Main variables
*/
var content = [{
title: "I Have Crush On You!!",
desc: ""
}, {
title: "I Have Crush On You!!",
desc: "Maybe it's a pretty simple sentence, a sentence that holds a lot of hope and doubt behind it. There is hope that wants the feeling of love not to fall alone, there is also something that must be prepared in order to accept the consequences."
}, {
title: "",
desc: "expressing feelings is a pretty serious thing, a lot will be sacrificed including the end result of releasing things that have been stored for a long time is quite a relief and not an easy thing. Here I just want to express my feelings for you, the problem is accepted or not it depends on you, I also won't expect more really."
}, {
title: "",
desc: "If you're uncomfortable just say, \"I have a crush on you\", if you already have a boyfriend, sorry... maybe that's all from me, hehe thanks for reading."
}, {
title: "I Have Crush On You!!",
desc: "I will wait for your reply :)"
}];
var currentPage = 0;
//generate content
for (var i = 0; i < content.length; i++) {
//split content letters to array
for (var obj in content[i]) {
//if string
if (typeof content[i][obj] === "string") {
content[i][obj] = content[i][obj].split("");
continue;
}
//if array (grouped text)
else if (typeof content[i][obj] === "object") {
var toPush = [];
for (var j = 0; j < content[i][obj].length; j++) {
for (var k = 0; k < content[i][obj][j].length; k++) {
toPush.push(content[i][obj][j][k]);
}
}
content[i][obj] = toPush;
}
}
//set text to
$("#segments").append("<div class=\"letters-wrap mutable\"><div class=\"soup-title\"></div><div class=\"soup-desc\"></div></div>");
setText();
//clone to data
$("#segments").append("<div class=\"letters-wrap position-data\"><div class=\"soup-title\"></div><div class=\"soup-desc\"></div></div>");
setText();
}
//initial arrangement
arrangeCurrentPage();
scrambleOthers();
/*
* Event handlers
*/
$(window).resize(function () {
arrangeCurrentPage();
scrambleOthers();
});
$("#soup-prev").hide();
$("#soup-prev").click(function () {
$("#soup-next").show();
currentPage--;
if (currentPage === 0) {
$("#soup-prev").hide();
}
arrangeCurrentPage();
scrambleOthers();
});
$("#soup-next").click(function () {
$("#soup-prev").show();
currentPage++;
if (currentPage === content.length - 1) {
$("#soup-next").hide();
}
arrangeCurrentPage();
scrambleOthers();
});
/*
* Functions
*/
function arrangeCurrentPage() {
for (var i = 0; i < content[currentPage].title.length; i++) {
$(".mutable:eq(" + currentPage + ") > .soup-title > .letter").eq(i).css({
left: $(".position-data:eq(" + currentPage + ") > .soup-title > .letter").eq(i).offset().left + "px",
top: $(".position-data:eq(" + currentPage + ") > .soup-title > .letter").eq(i).offset().top + "px",
color: "#111",
zIndex: 9001
});
}
for (var i = 0; i < content[currentPage].desc.length; i++) {
$(".mutable:eq(" + currentPage + ") > .soup-desc > .letter").eq(i).css({
left: $(".position-data:eq(" + currentPage + ") > .soup-desc > .letter").eq(i).offset().left + "px",
top: $(".position-data:eq(" + currentPage + ") > .soup-desc > .letter").eq(i).offset().top + "px",
color: "#111",
zIndex: 9001
});
}
}
function setText() {
var j;
for (j = 0; j < content[i].title.length; j++) {
$(".soup-title").last().append("<span class=\"letter\">" + content[i].title[j] + "</span>");
}
for (j = 0; j < content[i].desc.length; j++) {
$(".soup-desc").last().append("<span class=\"letter\">" + content[i].desc[j] + "</span>");
}
}
function scrambleOthers() {
for (var i = 0; i < content.length; i++) {
//don't scramble currentPage
if (currentPage === i)
continue;
var parts = [
["title", ".soup-title"],
["desc", ".soup-desc"]
];
//apply to .title h1s and .desc ps
for (var j = 0; j < parts.length; j++) {
for (var k = 0; k < content[i][parts[j][0]].length; k++) {
//define random position on screen
var randLeft = Math.floor(Math.random() * $(window).width());
var randTop = Math.floor(Math.random() * $(window).height());
//defining boundaries
var offset = $(".position-data").eq(currentPage).offset();
var bounds = {
left: offset.left,
top: offset.top,
right: $(window).width() - offset.left,
bottom: $(window).height() - offset.top
};
var middleX = bounds.left + $(".position-data").eq(currentPage).width() / 2;
var middleY = bounds.top + $(".position-data").eq(currentPage).height() / 2;
//finally, apply all the scrambles
$(".mutable:eq(" + i + ") > " + parts[j][1] + " > .letter").eq(k).css({
left: randLeft,
top: randTop,
color: "#DDD",
zIndex: "initial"
});
}
}
}
}
});