Created
July 13, 2012 19:47
-
-
Save sahinsf/3106985 to your computer and use it in GitHub Desktop.
jQ-30 Effects
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<title>Effect Speeds / Custom Effect Methods</title> | |
<style> | |
p { margin-top: 0;} | |
</style> | |
</head> | |
<body> | |
<h1>Reveal</h1> | |
<div class=content> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | |
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | |
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script> | |
$('div.content').hide(); | |
console.log(jQuery.fx.speeds); | |
//overriding _default | |
$.fx.speeds._default = 450; | |
$.fx.speeds.tortoise = 5000; | |
$('h1').on('click', function(){ | |
//$(this).next().slideDown(1000); | |
$(this).next().slideDown('slow'); //'fast': 200 //'_default': 400 | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<title>Custom Effect Methods</title> | |
<style> | |
p { margin-top: 0;} | |
</style> | |
</head> | |
<body> | |
<h1>Reveal</h1> | |
<div class=content> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | |
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | |
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script> | |
(function(){ //prevents global vars | |
var content = $('div.content').hide(); //all jquery methods returns the same object | |
//console.log(content) is still returning div.content object | |
$('h1').on('click', function() { | |
content.customEffect(); | |
}); | |
//what makes custom methods available to the jQuery prototype ==> jQuery.fn[name] | |
//jQuery.fn = jQuery object's prototype | |
jQuery.fn.customEffect = function( speed, easing, callback ) { | |
var $this = $(this); | |
//$(this).slideDown(500); | |
//console.log('try to see when animation is completed'); //before | |
return $this.slideDown(500, function(){ //passing a 2nd parameter => execute after animation completed | |
//console.log('this will log after the animation is completed'); | |
$this.delay(500).slideUp(500); //delay and slideUp after first animation completed | |
}); | |
}; | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment