forked from chriscoyier/Slides
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent window load event from happening too fast
- Loading branch information
1 parent
d6cb217
commit f3a9309
Showing
1 changed file
with
42 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,44 @@ | ||
$(window).load(function() { | ||
$("html").addClass("loaded"); | ||
}); | ||
|
||
function gotoThere(link) { | ||
window.location = link; | ||
} | ||
|
||
$("#previous, #next").click(function(e) { | ||
$("html").addClass("leaving"); | ||
setTimeout(gotoThere, 1500, this.href); | ||
return false; | ||
}); | ||
|
||
$("#jumper").change(function() { | ||
$("html").addClass("leaving"); | ||
setTimeout(gotoThere, 1500, $(this).val()); | ||
}); | ||
|
||
$(document).keydown(function(e) { | ||
// right arrow | ||
if (e.keyCode == 39) { | ||
$("#next").click(); | ||
} | ||
// left arrow | ||
if (e.keyCode == 37) { | ||
$("#previous").click(); | ||
$(function() { | ||
|
||
// Prevent window.load from happening too fast | ||
// Idea by Chris Coyier and debungled by Paul Irish | ||
(function fn() { | ||
fn.now = +new Date; | ||
|
||
$(window).load(function() { | ||
// 500ms seems to be enough... feel free to adjust per machine | ||
if (+new Date - fn.now < 500) setTimeout(fn, 500); | ||
$("html").addClass("loaded"); | ||
}); | ||
|
||
})(); | ||
|
||
// Simple redirect function | ||
function gotoThere(link) { | ||
window.location = link; | ||
} | ||
|
||
$("#previous, #next").click(function(e) { | ||
$("html").addClass("leaving"); | ||
setTimeout(gotoThere, 1500, this.href); | ||
return false; | ||
}); | ||
|
||
$("#jumper").change(function() { | ||
$("html").addClass("leaving"); | ||
setTimeout(gotoThere, 1500, $(this).val()); | ||
}); | ||
|
||
// Left and right arrow keys for changing slides | ||
$(document).keydown(function(e) { | ||
// right arrow | ||
if (e.keyCode == 39) { | ||
gotoThere($("#next").attr("href")); | ||
} | ||
// left arrow | ||
if (e.keyCode == 37) { | ||
gotoThere($("#previous").attr("href")); | ||
} | ||
}); | ||
|
||
}); |