TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Create JQuery Plugin
Prashant Verma
Nov 09
2015
Code
824
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
(function ($)
{
$.fn.changebg = function (options)
{
var settings = $.extend(
{
speed:
"1000"
,
color:
"#556b2f"
,
backgroundColor:
"white"
,
width:
"200px"
}, options);
return
this
.css(
{
color: settings.color,
backgroundColor: settings.backgroundColor,
width: settings.width
});
};
$.fn.moveright = function (options)
{
var settings = $.extend(
{
position:
"200px"
}, options);
return
this
.css(
{
'margin-left'
: settings.position,
'-webkit-transition'
:
'margin-left 2s'
,
transition:
'margin-left 2s'
});
return
this
;
};
}(jQuery));
Save The above as "
myplugin.js
",
<html>
<head>
<title>My jQuery Plugin</title>
<script src=
"http://code.jquery.com/jquery-1.11.0.js"
></script>
<script src=
"myplugin.js"
></script>
<script>
$(document)
.ready(function ()
{
$(
".animate"
)
.click(function ()
{
$(
this
)
.changebg(
{
backgroundColor:
"green"
,
color:
"white"
})
.moveright(
{
position:
"300px"
})
});
$(
".animate1"
)
.click(function ()
{
$(
this
)
.moveright(
{
position:
"500px"
})
});
});
</script>
<style type=
"text/css"
>
.animate {
height: 100px;
width: 100px;
background-color: red;
position: relative;
}
.animate1 {
height: 200px;
width: 200px;
background-color: yellow;
position: relative;
}
</style>
</head>
<body>
<div
class
=
"animate"
> my Plugin Animation </div>
<div
class
=
"animate1"
> my Plugin Animation </div>
</div>
</body>
</html>
Create Jquery Plugin
Jquery Plugin
Simple Jquery Plugin