2015-09-04 32 views
-3

我试图使用HTML和CSS来创建一个段落标记,当用户单击它时,从左向右移动。我该如何做这样的事情?如何使用jQuery在页面中移动元素?

+2

您是否尝试过这个吗?发布你的代码,给我们一些工作。我们在这里回答问题,但我们不在这里为您编写代码。 –

+1

我提供的答案是使用jQuery移动元素的通用方法,但是像@AdamBuchananSmith所说的,我们需要查看您所尝试的内容,以便我们可以从那里帮助您。 –

回答

1

您可以使用jQuery的animate来移动元素。请检查下面的例子:

$(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>

相关问题