-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.js
More file actions
49 lines (44 loc) · 1.32 KB
/
main2.js
File metadata and controls
49 lines (44 loc) · 1.32 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
var sentences = ["We are a boutique software development firm located in sunny *Beverly Hills, California*."];
var spans = [];
var positions = [];
function displaySentence() {
var sentence = sentences[Math.floor(Math.random()*sentences.length)];
var formattedSentence = "";
var inLink = false;
for (var i=0; i<sentence.length; i++) {
if (sentence[i] === "*") {
if (inLink) {
inLink = false;
formattedSentence += "</a>";
}
else {
inLink = true;
formattedSentence += "<a href='#'>";
}
}
else {
formattedSentence += "<span class='letter'>" + sentence[i] + "</span>";
}
}
$("#sentence").html(formattedSentence);
positions = [];
spans = $("#sentence span");
spans.each(function(i, elem) {
position = $(elem).offset();
positions.push(position);
});
}
$(function() {
displaySentence();
$(document).mousemove(function(e) {
for (var i=0; i<positions.length; i++) {
var position = positions[i];
dy = position.top - e.pageY;
dx = position.left - e.pageX;
if (dy*dy + dx*dx < 50) {
$(spans[i]).
console.log(position);
}
}
});
});