jquery使用animate方法实现控制元素移动
本文实例讲述了jquery使用animate方法实现控制元素移动。分享给大家供大家参考。具体分析如下:
通过jquery的animate方法控制元素移动,这里需要将元素的位置定义为relative,fixed,或者absolute!
<!DOCTYPEhtml> <html> <head> <scriptsrc="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("div").animate({left:'250px'}); }); }); </script> </head> <body> <button>StartAnimation</button> <p>Bydefault,allHTMLelementshaveastaticposition, andcannotbemoved.Tomanipulatetheposition, remembertofirstsettheCSSpositionproperty oftheelementtorelative,fixed,orabsolute!</p> <divstyle="background:#98bf21; height:100px;width:100px;position:absolute;"> </div> </body> </html>
希望本文所述对大家的jQuery程序设计有所帮助。