代码只能对以px为单位的样式进行改变。

js Code:

            function animate(ele,name,from,to,time) {
                time = time ||800;
                var interval,count,step,now;
                interval = 60;
                count =Math.round(time/interval);
                step = Math.round((to-from)/count);
                now = from;
                var style = document.getElementById(ele).style;
                function go() {
                    count--;
                    now = count?now+step:to;
                    style[name] = now + "px";
                    if(count) {
                        setTimeout(go,interval);
                    }
                }

                style[name] = from + 'px';
                setTimeout(go,interval);
            }

html Code:

        <p >
            <span id ='s1'>goole!!!!!goole</span>
        </p>
        <input type="button" value="changeSize" onclick="animate('s1','font-size',9,50,1000)">

 

 

相关文章:

  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2021-11-13
猜你喜欢
  • 2022-12-23
  • 2021-10-16
  • 2022-01-17
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案