-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
323 lines (260 loc) · 10.6 KB
/
index.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Basic.js - Examples</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background-color: #000;
min-height: 400px;
min-width: 600px;
}
p {
color: #fff;
}
.white {
color: #fff;
}
.black {
color: #000;
}
.italic {
font-style: italic;
}
.tests {
color: #444;
position: absolute;
bottom: 1em;
left: 1em;
}
.content {
width: 200px;
height: 100px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -100px;
text-align: center;
}
</style>
<script src="dist/basic.js"></script>
<script>
/* Basic.js usage examples */
console.log("Loading page...");
$(document).ready(function()
{
console.log("Page loaded!");
// Get the size of some elements
console.log("Size of .hello:", $('.hello').size('inner'));
console.log("Size of .world:", $('.world').size('outer'));
// Get the sizes of every matched element
console.log("Sizes of div, p:", $('div, p').size('both'));
// Adding and removing classes
setInterval(function()
{
if($('.world').hasClass('black'))
{
$('.world').removeClass('black');
}
else
{
$('.world').addClass('black');
}
}, 1000);
// Bind some events
$('.world').on('mousedown mouseup mouseenter mouseleave', function(event)
{
event.preventDefault();
// Get the current size
var size = parseInt($(this).style('font-size'));
// Convert from px to pt
size = Math.ceil(size * 0.75);
// INCREASE IT!!!
size++;
// SUPER INCREASE IT!!!
if(event.detail.super)
{
size += 10;
}
// Set the new size
$(this).style({'font-size': size + 'pt'});
});
// Hide hello world on click
$('.hello').on('click', function()
{
// "this" is a reference to the element where the event occurred
$(this).addClass('black');
console.log('*poof*');
});
// Find a child selector within a specific element
$('div').find('.hello').addClass('italic');
// Select specific elements within a matched selector
$('.dots .dot').eq(3).addClass('white');
$('.dots .dot').eq(randomInt(0, 9)).addClass('white');
// Clear the dots after 1 second
setTimeout(function()
{
$('.dot').removeClass('white');
}, 1000);
// Loop over all dots and do something else
$('.dot').each(function(index, element)
{
setTimeout(function()
{
$(element).addClass('white');
}, 1100 + (index * 100));
});
// Change the style of an element
$('.dots').style({'color': '#111', 'font-size': '30pt'});
// Get the position of an element (relative to the page)
console.log($('.hello').position());
// Get the position of an element (relative to the window)
console.log($('.hello').position('window'));
// Find the scroll position of the window
$(window).on('scroll', function()
{
console.log("Window scroll position:", $(this).scroll());
console.log($('.hello').position());
console.log($('.hello').position('window'));
});
// Trigger an event
$('.trigger').on('click', function()
{
$('.world').trigger('mousedown', {super: true});
});
// Modify the content of some elements using strings
$('.html').html("<b>Magic~</b>");
$('.text').text("<u>Can't hack me!</u>");
$('.example').prepend("Nice to meet you.");
$('.example').append("See you later!");
// Modify the content of elements using other elements
var generated = document.createElement('p');
$(generated).text('This is a generated element!');
$(generated).style({'font-size': '5pt'});
$('.example').prepend(generated);
$('.example').append(generated);
// Replace an element entirely
$('.replace').replace("<b>Replaced!</b>");
// Remove an element
$('.remove').remove();
// Modify some attributes
$('.attr').attr('sweet', 'bro');
$('.attr').attr('remove', false);
$('.check').attr('checked', true);
// Get the value of an attribute
console.log($('.attr').attr('sweet'));
// Modify some data attributes
$('.data').data('sweet', 'bro');
$('.data').data('awesome', 'thanks');
// Get the value of a data attribute
console.log($('.data').data('test'));
// Let's look at the whole dataset
console.log($('.data').el[0].dataset);
// Set the value of an input
$('.set').value('This is also a value!');
// Get the value of an input
console.log($('.get').value());
// Check if an element is checked
if($('.uncheck').prop('checked'))
{
console.log("It's checked!");
// Uncheck it
$('.uncheck').prop('checked', false);
}
function addDot()
{
// Clone a dot
var dot = $('.dot').clone()[0];
// Add it to the list of dots
$('.dots').append(dot);
$('.dots').append(' ');
console.log($('.dot').length);
}
// Bind an event that only fires when a child selector is matched
$('body').on('click', '.dot', addDot);
// Stop adding dots if you click on hello world
$('body').on('click', '.hello', function()
{
if(!$(this).hasClass('black magic'))
{
$(this).addClass('magic');
}
else
{
console.log("Spooky black magic!!~");
}
$('body').off('click', '.dot', addDot);
});
// Apply some CSS transformations
$('.transform').transform('rotate', '30deg');
$('.transform').transform('translate', '150px', '-150px');
$('.transform2').transform({rotate: '29deg', translate: ['165px', '-145px']});
// Get an element's parent
console.log($('.hello').parent());
console.log($('.child').parents('.parent'));
// Toggling elements
$('button.toggle').on('click', function()
{
$('.toggle.one').toggle();
$('.toggle.two').toggle('white');
});
});
</script>
<script>
/* Miscellaneous helper functions */
// Thanks MDN
function randomInt(min, max)
{
return Math.floor(Math.random() * (max - min)) + min;
}
</script>
</head>
<body>
<div class="dots">
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
<span class="dot">.</span>
</div>
<div class="tests">
<div class="html"></div>
<div class="text"></div>
<div class="example">
<div>This is some example content</div>
</div>
<div class="replace"></div>
<div class="remove"></div>
<div class="attr" remove="me"></div>
<input class="check" type="checkbox">
<input class="uncheck" type="checkbox" checked>
<div class="data" data-test="this is some data!"></div>
<input class="get" value="This is a value!">
<input class="set" value="">
<div class="transform">I'm transforming!!!</div>
<div class="transform2">Meee tooo!!</div>
<div class="toggle one">This is some text</div>
<div class="toggle two white">So is this!</div>
</div>
<div class="content">
<p class="hello">Hello world!</p>
<p class="world">*blink*</p>
<button class="trigger">Make it grow</button>
<button class="toggle">Toggle Stuff</button>
</div>
<div class="parent">
<div class="wrap">
<div class="child"></div>
</div>
</div>
</body>
</html>