css动画小效果

1、按钮滑动效果

这是我第一次在csdn发表博客,只是想把一些效果还有一些问题的解决方案写下来方便新手的查阅,也想通过这个方法把平常遇到的问题记录下来以便日后查看,也给大家一些参考,如果大家有更好的解决方案欢迎来评论,望与君共同进步,丘~

点击按钮可以滑动

<style>
        div{
            width: 100px;
            height: 50px;
            border-radius: 25px;
            cursor: pointer;
            background-color: lightblue;
        }
        p{
            width: 50px;
            height: 50px;
            border-radius: 100%;
            background-color: lightcoral;
            transform: translateX(0);
            transition: transform 500ms;
        }
        p.on{
            transform: translateX(50px);
            transition: transform 500ms;
        }
    </style>
</head>
<body>
    <div>
        <p></p>
    </div>
</body>
</html>
<script>
    var p = document.querySelector('div p');
    var anniu = document.querySelector('div');
    var open = true;
    anniu.onclick = function(){
        if(open){
            p.classList.add('on');
            open = false
        }else{
            p.classList.remove('on')
            open = true;
        }
    }
</script>

2、css三角箭头点击旋转##

这里写图片描述
首先我们先用一个span空标签加上css样式写出一个三角形,下面我写的这个是箭头朝上的效果,如果需要箭头为其他方向的效果,通过改变border-bottom-color就行了,当然如果你不想用css写三角形的样式,也可以采用图片去写,然后绑定下面的点击事件就可以啦。

  <style>
      span{
        display: inline-block;
        border: 10px solid transparent;
        border-bottom-color: lightcoral;//箭头朝上
        transform: rotate(0);
        transform-origin:70% 70%;
        transition: 100ms;
        margin: 100px;
      }
      span.on{
        transform: rotate(90deg);
        transform-origin:70% 70%;
        transition: 100ms;
      }
    </style>
</head>
<body>
  <span></span>
</body>
</html>
<script>
    var span = document.querySelector('span');
    var open = true;
    span.onclick = function(){
        if(open){
            span.classList.add('on');
            open = false
        }else{
            span.classList.remove('on')
            open = true;
        }
    }
</script>

3、文字跳动效果

我这里没有动图,大致效果就是文字变大变小,像是gif动图。
这里写图片描述
这里写图片描述


<style>
  div{
      width: 100px;
      height: 50px;
      line-height: 50px;
      background-color: lightblue;
      text-align: center;
  }
</style>
</head>
<body>
    <div>
        <span>我是大魔王</span>
    </div>
</body>
</html>
<script>
    var p = document.querySelector('span');
    var da = true;
    setInterval( function(){
            if(da){
                p.style.fontSize = '18px';
                da = false
            }else{
                p.style.fontSize = '14px';
                da = true
            }
    },500)
</script>

4.无限旋转动画

这个常用于加载动画

@-webkit-keyframes rotation{
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}

.circle{
-webkit-transform: rotate(360deg);
animation: rotation 1s linear infinite;
-moz-animation: rotation 1s linear infinite;
-webkit-animation: rotation1s linear infinite;
-o-animation: rotation 1s linear infinite;
}

然后给需要旋转动画的标签加上class类名 “circle” 就可以了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值