forked from MihirSachdeva/InformationManagementGames
/
index.js
136 lines (108 loc) · 3.74 KB
/
index.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
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
// TYPING EFFECT CODE STARTS
var TxtType = function(el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtType.prototype.tick = function() {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 200 - Math.random() * 100;
if (this.isDeleting) {
delta /= 2;
}
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function() {
that.tick();
}, delta);
};
window.onload = function() {
var elements = document.getElementsByClassName('typewrite');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-type');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtType(elements[i], JSON.parse(toRotate), period);
}
}
};
//TYPING EFFECT CODE ENDS
//NAV BAR LINK SCROLL EFFECT CODE STARTS
$('#gamesLink').on('click', function(){
scrollToElem('#element1')
});
function scrollToElem(element){
var position = $(element).offset().top;
var duration = getDuration(position);
$("HTML, BODY").animate({
scrollTop: position
}, duration);
}
function getDuration(target) {
var currentTop = $(window).scrollTop(), rate = 0.5, distance;
distance = Math.abs(currentTop - target);
return distance * rate;
}
$("#homeLink").on('click', function(){
var duration = getDuration(0);
$("HTML, BODY").animate({
scrollTop: 0
}, duration);
});
//NAV BAR LINK SCROLL EFFECT CODE ENDS
// BORED BUTTON CODE STARTS
var gameLinks=["https://ayu023ban.github.io/tic-tac-toe/","https://gauransh7.github.io/car-traffic/","https://kmrinal19.github.io/pocketTanks/","https://sparsh1212.github.io/Mid-sem_Assignment_Sparsh/","https://mihirsachdeva.github.io/FlappyBird/","https://aitalshashank2.github.io/ChessEngine/index.html","https://prernaswarna.github.io/Gamejavacript/","https://shreyasdoda.github.io/connect-four-hosted/","https://geekvert.github.io/Minesweeper/","https://bpraak.github.io/Memory/","https://rochakjain361.github.io/snakeGame/snakes.html","https://ktg-123.github.io/PingPong.html","https://ruddi10.github.io/ping-pong/","https://yash523.github.io/game.html","https://gopalgupta8216.github.io/game/Snake.html","https://gagansh7171.github.io/js-game/"]
function boredButtonClick(){
let linkLength= gameLinks.length
let random_num = Math.floor(Math.random()*linkLength)
window.location.href=gameLinks[random_num]
}
// BORED BUTTON CODE ENDS
//SIDENAV CODE STARTS
var sideopen = false;
$('#nav-icon3').click(function(){
$(this).toggleClass('open');
if(sideopen){
closeNav();
} else{
document.getElementById("sidenav").style.width = "250px";
sideopen = true;
}
});
$('#gamesLinkS').on('click', function(){
$('#nav-icon3').toggleClass('open');
closeNav();
scrollToElem('#elementsGridMobile')
});
$("#homeLinkS").on('click', function(){
$('#nav-icon3').toggleClass('open');
closeNav();
var duration = getDuration(0);
$("HTML, BODY").animate({
scrollTop: 0
}, duration);
});
/* Set the width of the side navigation to 0 and the left margin of the page content to 0, and the background color of body to white */
function closeNav() {
sideopen = false;
document.getElementById("sidenav").style.width = "0";
}
//SIDENAV CODE ENDS