css3 由小变大然后一直旋转的动画怎么做

html-css011

css3 由小变大然后一直旋转的动画怎么做,第1张

这个只用css不能完全实现,的配合js的定时器来完成,下面是代码:

<!DOCTYPE html>  

<html>  

<head>  

    <title>HTML5</title>  

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />  

    <style type="text/css">

        img{width: 200px}

        .div1{width: 200pxheight: 200pxborder:1px solid #000margin: 150px auto}

        .animate1{

            -webkit-animation:  move1 2s infinite

        }

        .animate2{

            -webkit-animation:  move2 1s infinite

        }

        @-webkit-keyframes move1{

            0%{

                -webkit-transform:scale(1)

            }

            100%{

                -webkit-transform:scale(1.5)

            }

        }

        @-webkit-keyframes move2{

            0%{

                -webkit-transform: rotateZ(0deg) scale(1.5)

                -webkit-transform:

            }

            100%{

                -webkit-transform: rotateZ(360deg) scale(1.5)

            }

        }

    </style>

</head>  

<body> 

    <div class="div1 animate2"></div>

    <script type="text/javascript">

        window.onload=function(){

            var oDiv=document.querySelector(".div1")

            oDiv.className="div1 animate1"

            setTimeout(function(){

                oDiv.className="div1 animate2"

            },2000)

        }

    </script>  

</body>  

</html>

原理是:当animate1执行完后,把这个class去掉,换成animate2。其中animate1的执行时间,刚好是js定时器的时间。

当然这里有个问题,js定时的时间不一定会非常的吻合css的动画时间,你可以根据情况作出适当的时间调整。

对于像<textarea>这样可以设置overflow属性的元素,css3提供了一个resize的方法,让用户可以通过拖拽来改变框体的大小。

注意:目前只有webkit核心浏览器才支持resize属性,且只支持等比例调整

一、resize改变输入框的大小

resize属性的选项参数:

none:用户无法调整元素的尺寸

both:用户可以调整元素的高度和宽度

horizontal:用户可调整元素的宽度

vertical:用户可调整元素的高度

注意:目前只有webkit核心浏览器才支持resize属性,且只支持等比例调整

二、resize属性默认是打开的

如果想关闭resize有两种方法:

1、通过resize属性禁止对元素进行缩放。

textarea{resize: none}

例子:

css部分:

body{

    background:goldenrod

}

.box1{

    resize: none

}

html部分:

<textarea>resize属性默认是打开的</textarea>

<br/><br/><br/>

<textarea class="box1">resize禁止对元素缩放</textarea>

2、限制文本框的最大及最小宽、高。

例子:

css部分:

.box4{

    max-height: 200px

    min-height: 200px

    height: 200px

    max-width: 200px

    min-width: 200px

    width: 200px

}

html部分:

<textarea class="box4">现在文本宽的最大及最小宽、高</textarea>

三、如何只改变输入框的高度或宽度

例子:

html部分:

<textarea class="box2">可调整元素的宽度</textarea>

<br/><br/><br/>

<textarea class="box3">可调整元素的高度</textarea>

css部分:

.box2{

    resize: horizontal

}

.box3{

    resize: vertical

}

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:body{background: url(image.jpg) no-repeatbackground-size: 200px 200px}。

3、浏览器运行index.html页面,此时背景图片成功被设定为200*200。