jquery animate .css

前端 未结 5 1465
醉梦人生
醉梦人生 2020-12-05 13:55

I have a script:

$(\'#hfont1\').hover(
    function() {
        $(this).css({\"color\":\"#efbe5c\",\"font-size\":\"52pt\"}); //mouseover
    }, 
    function         


        
5条回答
  •  一个人的身影
    2020-12-05 14:23

    If you are needing to use CSS with the jQuery .animate() function, you can use set the duration.

    $("#my_image").css({
        'left':'1000px',
        6000, ''
    });
    

    We have the duration property set to 6000.

    This will set the time in thousandth of seconds: 6 seconds.

    After the duration our next property "easing" changes how our CSS happens.

    We have our positioning set to absolute.

    There are two default ones to the absolute function: 'linear' and 'swing'.

    In this example I am using linear.

    It allows for it to use a even pace.

    The other 'swing' allows for a exponential speed increase.

    There are a bunch of really cool properties to use with animate like bounce, etc.

    $(document).ready(function(){
        $("#my_image").css({
            'height': '100px',
            'width':'100px',
            'background-color':'#0000EE',
            'position':'absolute'
        });// property than value
    
        $("#my_image").animate({
            'left':'1000px'
        },6000, 'linear', function(){
            alert("Done Animating");
        });
    });
    

提交回复
热议问题