Reputation: 273
I want to convert my CSS transition to Jquery
My CSS transition is this :
.classname {
width : 470px;
transition: all 2s ease 0s;
}
.classname:hover {
width : 700px;
}
this mean the CSS code , changes the width of element .
So, How can i do that with Jquery ?
Upvotes: 0
Views: 117
Reputation: 28588
You should try hover() with animate(). try this:
$(".classname").hover( function(){
$(this).animate({width : '700px'});
}, function(){
$(this).animate({width : '470px'});
})
Upvotes: 0
Reputation: 6411
Try this:
http://jsfiddle.net/aamir/QGc8h/
HTML:
css:<br/>
<div class='classname'>some content</div>
jquery:<br/>
<div class='jqclassname'>some content</div>
CSS:
.jqclassname, .classname {
border: 1px solid red;
width : 470px;
}
.classname {
transition: all 2s ease 0s;
}
.classname:hover {
width : 700px;
}
JS:
$(function(){
$('.jqclassname').hover(
function(){
$(this).stop().animate({width: 700}, 2000);
},
function(){
$(this).stop().animate({width: 470}, 2000);
}
)
});
Upvotes: 0
Reputation: 1489
$(document).ready(function(){
$(".classname").hover( function(){
$(this).delay(2000).animate({width : 700px});
}, function(){
$(this).delay(2000).animate({width : 470px});
});
});
Upvotes: 0
Reputation: 3039
What all you need to do is to add an event on your class, and then attach animate method to it. you can see these kind of examples of learn.jquery.com as well.
$(".classname").on({
mouseenter : function(){
$(this).animate({
width : 700
});
},
mouseleave : function(){
$(this).animate({
width : 470
});
}
});
jsfiddle: http://jsfiddle.net/w5pRy/1/
Upvotes: 1
Reputation: 3667
$(".classname").hover(function () {
$(this).animate({
width: "300px"
});
}, function () {
$(this).animate({
width: "100px"
});
});
working Fiddle
Upvotes: 0
Reputation: 894
Try this solution
$('body').on('mouseenter', '.classname', function(){
$(this).animate({width : 700});
}).on('mouseleave', '.classname', function(){
$(this).animate({width : 470});
})
Upvotes: 0