Using jQuery to change div width from 50% to 70% on hover

后端 未结 3 1422
我寻月下人不归
我寻月下人不归 2021-01-13 12:12

I have two divs that have 50% width each. I want to make it so that the the hovered div expands to 70% and the other reduces to 30%. And when the mouse moves out, they both

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 12:37

    To take @James' answer (+1) and add animation, just use .animate():

    $(function(){
        $("#div1").hover(
            function(){
               $(this).animate({width: '70%'});
            },
            function(){
                $(this).animate({width: '50%'});
            }
        );                            
    });
    

    Demo: http://jsfiddle.net/mattball/sAW2c/

提交回复
热议问题