摘要: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jquery自定義動(dòng)畫(huà)效果</title> &n
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jquery自定義動(dòng)畫(huà)效果</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> <style> div{ width:200px; height:200px; margin:20px 0; } .box1{ width:100px; height:100px; background: red; position:absolute; } .box2{ width:100px; height:100px; background: blue; position: absolute; } .box3{ width:100px; height:100px; background: yellow; position: absolute; } .box4{ width:100px; height:100px; background: pink; position: absolute; } </style> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $('.but1').click(function(){ $('p').animate({fontSize:'40px'},1500) //屬性名稱font-size改寫(xiě)成駝峰式寫(xiě)法:fontSize }) $('.but2').click(function(){ $('.box1').animate({ left:'400px', width:'200px', height:'200px', opacity:'0.4', },1500) }) $('.but3').click(function(){ $('.box2').animate({height:'toggle',width:'toggle'},1500) }) $('.but4').click(function(){ $('.box3').animate({height:'hide',width:'hide'},1300) }) $('.box4').hide() $('.but5').click(function(){ $('.box4').animate({height:'show',width:'show'},1000) }) }) </script> <button class="but1">點(diǎn)擊字體放大</button> <p>jquery中我們使用animate()方法創(chuàng)建自定義動(dòng)畫(huà)</p> <div > <button class="but2">點(diǎn)擊移動(dòng)</button> <div class="box1"></div> </div> <div > <button class="but3">點(diǎn)擊切換</button> <div class="box2"></div> </div> <div> <button class="but4">點(diǎn)擊隱藏</button> <div class="box3"></div> </div> <div> <button class="but5">點(diǎn)擊顯示</button> <div class="box4"></div> </div> </body> </html>>