摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery淡入淡出</title> <script type="text/javascript" src="j
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery淡入淡出</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> <style> div{width: 200px;height: 200px;background: blue;position: absolute;} </style> </head> <body> <!-- jQuery中我們使用 animate() 方法創(chuàng)建自定義的動(dòng)畫(huà) 語(yǔ)法:$(selector).animate({params},speed,fn); 必需的 params 參數(shù)定義形成動(dòng)畫(huà)的css屬性。 可選的 speed 參數(shù)規(guī)定效果的時(shí)長(zhǎng)。它可以取以下值:"slow"、"fast"或者毫秒。 可選的 fn 是動(dòng)畫(huà)完成后所執(zhí)行的函數(shù) stop() 方法用于停止動(dòng)畫(huà)或效果,在它們完成之前 該方法適用于所有jQuery效果函數(shù),包括滑動(dòng)、淡入淡出和自定義動(dòng)畫(huà)。 語(yǔ)法:$(selector).stop(stopAll,goToEnd) 可選的參數(shù) stopAll 規(guī)定是否應(yīng)該清除動(dòng)畫(huà)隊(duì)列。默認(rèn)是 false 僅停止活動(dòng)的動(dòng)畫(huà),允許任何排入隊(duì)列的動(dòng)畫(huà)向后執(zhí)行 可選的參數(shù) goToEnd 規(guī)定是否立即完成當(dāng)前動(dòng)畫(huà)。默認(rèn)是 false 默認(rèn)情況下 stop() 會(huì)清除在被選元素上指定的當(dāng)前動(dòng)畫(huà) --> <script type="text/javascript"> $(document).ready(function(){ $('.but1').click(function(){ $('p').animate({fontSize:'40px'},1000)//屬性名稱font-size 一律改成駝峰寫(xiě)法 }) //同時(shí)操作多個(gè)CSS屬性 $('.but2').click(function(){ $('div').animate({ left:'400px', opacity:'0.3', height:'400px',//height:'toggle' width:'toggle'//width:'400px' },1500) }) }) </script> <button>點(diǎn)擊字體放大</button> <p>jQuery中我們使用 animate() 方法創(chuàng)建自定義的動(dòng)畫(huà)</p> <button>點(diǎn)擊移動(dòng)div</button> <div></div> </body> </html>