layui官方文檔晦澀難懂,對小白特別不友好css
爲演示效果,js和css文件引用cdnhtml
演示是ul套li標籤進行演示,這不是固定的,你也能夠div套div,div套span,外面和裏面的標籤類要一一對應就行jquery
官方文檔演示沒有提js語句的使用,直接寫html代碼是沒有動畫效果的,因此須要使用layui的js語句oop
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>layui動畫測試</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css"> <script src="https://www.layuicdn.com/layui/layui.js"></script> <style> .site-doc-icon li .layui-anim { width: 150px; height: 150px; line-height: 150px; margin: 0 auto 10px; text-align: center; background-color: #009688; cursor: pointer; color: #fff; border-radius: 50%; } </style> </head> <body> <ul class="site-doc-icon site-doc-anim"> <li> <div class="layui-anim" data-anim="layui-anim-up">從最底部往上滑入</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-upbit">微微往上滑入</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-scale">平滑放大</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-scaleSpring">彈簧式放大</div> </li> </ul> <ul class="site-doc-icon site-doc-anim"> <li> <div class="layui-anim" data-anim="layui-anim-fadein">漸現</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-fadeout">漸隱</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-rotate">360度旋轉</div> </li> <li> <div class="layui-anim" data-anim="layui-anim-rotate layui-anim-loop">循環動畫</div> </li> </ul> <script> layui.use([], function () { var $ = layui.jquery; //演示動畫開始 $('.site-doc-icon .layui-anim').on('click', function(){ var othis = $(this), anim = othis.data('anim'); //中止循環 if(othis.hasClass('layui-anim-loop')){ return othis.removeClass(anim); } othis.removeClass(anim); setTimeout(function(){ othis.addClass(anim); }); //恢復漸隱 if(anim === 'layui-anim-fadeout'){ setTimeout(function(){ othis.removeClass(anim); }, 1300); } }); //演示動畫結束 }) </script> </body> </html>