简体   繁体   English

如何使用 jQuery 在页面上移动元素?

[英]How do I move an element across the page using jQuery?

I'm trying to use HTML and CSS to make a paragraph tag move form left to right when the user clicks it.我正在尝试使用 HTML 和 CSS 使段落标记在用户单击时从左向右移动。 How can I do something like this?我怎么能做这样的事情?

You can use jQuery's animate to move elements.您可以使用 jQuery 的animate来移动元素。 Check the following example:检查以下示例:

 $(document).ready(function(){ $("button").click(function(){ $(".text-box").animate({left: '250px'}); }); });
 .text-box{ background:#98bf21; height:auto; max-width:400px; width:auto; position:absolute; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <button>Move Element!!</button> <div class="text-box""><p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM