0

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 ?

2

6 Answers 6

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

Try this solution

$('body').on('mouseenter', '.classname', function(){
   $(this).animate({width : 700});
}).on('mouseleave', '.classname', function(){
  $(this).animate({width : 470});
})

Comments

0
$(".classname").hover(function () {
        $(this).animate({
            width: "300px"
        });
    }, function () {
        $(this).animate({
            width: "100px"
        });

    });

working Fiddle

Comments

0
$(document).ready(function(){

   $(".classname").hover( function(){
   $(this).delay(2000).animate({width : 700px});
   }, function(){
   $(this).delay(2000).animate({width : 470px});
   });

});

Comments

0

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);
        }
    )
});

Comments

0

You should try hover() with animate(). try this:

$(".classname").hover( function(){
 $(this).animate({width : '700px'});
}, function(){
 $(this).animate({width : '470px'});
})

Here is working demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.