前端写特效的时候必须要保证DOM是加载完毕的,之前我用组件生命周期的update写,多有不便,
现发现自定义指令比较好,指令里面也是有周期,能做到相对的分离,案例奉上
html 代码
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<style type="text/css">
*{padding: 0;margin:0;}
ul,li{list-style: none}
.sliderCon{
width: 800px;
height: 400px;
margin: 50px auto;
overflow: hidden;
font-family: "微软雅黑";
position: relative;
}
.sliderCon ul{
position: absolute;
left: 0;
top: 0
}
.sliderCon ul li{
width: 800px;
height: 100%;
line-height: 400px;
text-align: center;
font-size: 50px;
color: #fff;
float: left