css3怎样让按钮从右上角滑动出来

html-css013

css3怎样让按钮从右上角滑动出来,第1张

像这种需求你可以用js或者jQuery编写。

如果不想使用js或者jquery,那么用css的过渡属性代码如下:

鼠标滑入,出现效果

transition: right  .7s ease

right为过渡的属性,可以是宽高,top/lelft/right/bottom/opacity等等。只要记住transition不能过渡display就行。

.7s 为过渡所需要的时间,ease为过渡的样式,是匀速过渡还是先快后慢等等。

如果没有鼠标事件,那么就需要用到css3的动画,animation。css3的动画详情卡查看https://mengkedu.com/

自动移动,目前css3是有这样的效果的,叫做css3动画

给你一个示例

你要注意的一点是目前这个只能支持最低为IE10及以上版本才能够运行的哦

Chrome 和 Safari 需要前缀 -webkit-。

本答案出自“我要编程”软件开发师训练平台免费课程。

<!DOCTYPE html>

<html>

<head>

<style> 

div

{

width:100px

height:100px

background:red

position:relative

animation:myfirst 5s

-moz-animation:myfirst 5s /* Firefox */

-webkit-animation:myfirst 5s /* Safari and Chrome */

-o-animation:myfirst 5s /* Opera */

}

@keyframes myfirst

{

0%   {background:red left:0px top:0px}

25%  {background:yellow left:200px top:0px}

50%  {background:blue left:200px top:200px}

75%  {background:green left:0px top:200px}

100% {background:red left:0px top:0px}

}

@-moz-keyframes myfirst /* Firefox */

{

0%   {background:red left:0px top:0px}

25%  {background:yellow left:200px top:0px}

50%  {background:blue left:200px top:200px}

75%  {background:green left:0px top:200px}

100% {background:red left:0px top:0px}

}

@-webkit-keyframes myfirst /* Safari and Chrome */

{

0%   {background:red left:0px top:0px}

25%  {background:yellow left:200px top:0px}

50%  {background:blue left:200px top:200px}

75%  {background:green left:0px top:200px}

100% {background:red left:0px top:0px}

}

@-o-keyframes myfirst /* Opera */

{

0%   {background:red left:0px top:0px}

25%  {background:yellow left:200px top:0px}

50%  {background:blue left:200px top:200px}

75%  {background:green left:0px top:200px}

100% {background:red left:0px top:0px}

}

</style>

</head>

<body>

<p><b>注释:</b>本例在 Internet Explorer 中无效。</p>

<div></div>

</body>

</html>

像这种效果,你要想知道,

已经下载下来,你拆开看一下就知道了。

说说原理,这里并不是纯css3,,只是用css3定义好动画,

@-moz-keyframes tips {

0% {box-shadow: 0px 0px 0px #f00}

25% {box-shadow: 0px 0px 8px #f00}

50% {box-shadow: 0px 0px 0px #f00}

100% {box-shadow: 0px 0px 8px #f00}

}

然后,js在切屏后,用Js来触发这一个样式,这个样式调用了刚才定义的动画。

.tips {

-webkit-animation:tips 1s

-moz-animation:tips 1s

}

当然css3是可以做的,只是用纯css3,就没办法像这样可以拖动切屏,这个是需要js或者jq来完成。。。