绝对定位居中、动画

绝对定位居中、动画

绝对定位居中

/*其余需要的属性自行添加*/
div{
	left:50%;
	transform:translateX(-50%);
}

动画(两种)
1.transition
2.animation

  1. 利用transition实现简单的div向右滑动效果
div{
	position:absolute;
	transition: transform .3s cubic-bezier(0.65,0.05,0.36,1)
	/*
	transform为需要动画效果的属性(具体参数类型查看官方文档)
	.3为执行动画需要的时间
	cubic-bezier(...)为动画的曲线
	*/
}

然后通过js代码设置需要改变div的transform属性

//state.property为触发滑动的条件
<div style=
{{tranform:state.property?"translateX(0)":"translateX(180px)"}}>
向右滑动条</div>
  1. 利用transition实现简单toast效果
div{
	animation:toast 3s;/*toast为动画命名 3s为动画执行时间*/
	animation-direction:alternate;
	/*alternate使动画先向前执行再向后执行*/
	/*其余参数参考官方文档*/
}
/*上文定义的动画名称*/
/*25% 50% 75%三个相同的属性设置是为了实现toast下滑时停留的效果*/
@keyframes toast{
	0%{top:0,opacity:0}
	25%{top:50px,opacity:1}
	50%{top:50px,opacity:1}
	75%{top:50px,opacity:1}
	100%{top:0,opacity:0}	
}

/*换成translateY效果会更流畅*/
/*如下:*/
@keyframes toast{
	0%{transform:translateY(0),opacity:0}
	25%{transform:translateY(150px),opacity:1}
	50%{transform:translateY(150px),opacity:1}
	75%{transform:translateY(150px),opacity:1}
	100%{transform:translateY(0),opacity:0}	
}

/*以上两种皆可*/

p元素如何在th里居中

th{
	vertical-align: middle;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值