2015-09-04 35 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>

相關問題