この例では、jqueryを使用して検索フィールドをアニメーション化し、divoninputを含む検索フィールドの先頭に移動しようとしています。私はもともとscriptaculouseffect.moveを使用してこれを実行していましたが、イベントを1回だけ発生させることはできなかったため、最初のキーストロークの後で誰かが入力し続けると、エフェクトは停止し、それぞれのアニメーションの現在の位置から再開します。愚かな追加のキーストローク。私はjqueryを初めて使用するので、あまり意味がない場合は気楽に行ってください。
編集:ocanalが投稿した例は間違いなく機能しますが、それを適用すると、何らかの理由で機能しません-これが現在のところです-同じイベントでdivをフェードしようとしています
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Untitled</title>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#search').keypress(function() {
$(this).animate({
top: '0',
});
$('#icon).fadeOut('slow', function() {
});
});
</script>
<style type="text/css" media="screen">
body {
margin: 0px;
padding: 0px;
}
#container {
position: relative;
border: #000 1px solid;
margin: 0px auto;
width: 960px;
height: 800px;
}
input {
outline: none;
}
#icon {
position: absolute;
top: 80px;
left: 370px;
width: 200px;
}
#search {
position: absolute;
top: 300px;
left: 230px;
width: 500px;
}
</style>
</head>
<body>
<div id="container">
<img id="icon" src="icon.png" alt="icon">
<input id="search" type="text" autofocus="autofocus">
</div>
</body>
</html>