如何用js给css3中的属性和jquery中的animate动态传值

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<script src="jquery-1.11.3.js" type="text/javascript"></script>
<style> 
.line{  
    width:400px;
    height:10px;
    transform:rotate(0deg);
    -ms-transform:rotate(0deg); /* IE 9 */
    -webkit-transform:rotate(0deg); /*Safari and Chrome */
    position:absolute;
    top:203px;
}
.fu{
    width:400px;
    height:400px;
    background-color:#f99;
    border-radius:50%;

}
.zi{
    width:200px;
    height:10px;
    background-color:yellow;
    overflow: hidden;
}
</style>
<script>
    $(function(){
        //animate动态传参  解决css3非数字参数,例如rotate(45deg),无法使用css()方法
        var time=1110;
        $('.line').animate(
            { textIndent: time },
            {step: function(now,fx) {
                                    $(this).css({
                                        '-webkit-transform':'rotate('+now+'deg)',
                                        'transform':'rotate('+now+'deg)',
                                        '-ms-transform':'rotate('+now+'deg)'
                                        });
                                    },
                                    duration:2000,     //time
                                    easing: "linear"  //运动轨迹 
                                    //easing: "swing"
            });

        //动态传参 单一属性
        var t=40;
        $(".line").css({
            'transform':'rotate('+t+'deg)'
        });

        //动态传参 复合属性
        function foo(a,b,c,d){
            $(".fu").css({
                'transform':'translate'+a+'px,'+b+'px)'+'rotate('+c+'deg)'+'scale('+d+')'
            });
        }
        foo(150,200,40,1.5);    
})
</script>
</head>
<body>
    <div class='fu'>
        <div class='line'>
            <div class="zi"></div>
        </div>
    </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘斩仙的笔记本

富贵险中求

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值