Skip to content

Instantly share code, notes, and snippets.

@hemantajax
Created May 26, 2012 16:08
Show Gist options
  • Save hemantajax/2794458 to your computer and use it in GitHub Desktop.
Save hemantajax/2794458 to your computer and use it in GitHub Desktop.
jquery plugin best practice
<!doctype html>
<html>
<head>
<title>My Info</title>
<meta charset="utf-8" />
<style>
#wrapper{
width:220px;
height:420px;
margin:40px auto;
}
#mypic,#myinfo{
width:278px;
height:250px;
border:10px solid #f0f0f0;
}
#myinfo{
width:258px;
background-color: #0ff;
padding:10px;
margin: 20px 0px;
display: none;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="mypic">
<img src="http://hemantajax.kodingen.com/portfolio/html5-portfolio/images/me.jpg" alt="Me" />
</div>
<div id="myinfo">
<h2>Contact Detail:</h2>
<div>Hemant Kumar Singh</div>
<div>Email: [email protected]</div>
<div>Phone: +91 7799111008</div>
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
(function(){
$.fn.fadeSlideToggle=function(speed,cb){
return this.animate({
height:"toggle",
opacity:"toggle"
},speed || 3000,function(){
$.isFunction(cb) && cb();
});
};
$('<button></button>', {
text: 'Fade Slide Toggle'
}).appendTo("#mypic")
.on("click",function(){
$("#myinfo").fadeSlideToggle(1000,function(){
console.log("Done...");
});
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment