jquery에 다음 코드가 있습니다. 내가 코드를 실행하면 jquery 버튼 클릭이 예상대로 결과를 반환하지 않습니다.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#button1").click(function() {
alert(1)
var div = $("div");
div.animate({
left: '100px'
}, "slow");
div.animate({
fontSize: '3em'
}, "slow");
});
$("button").click(function() {
alert(3)
var div = $("div");
div.animate({
left: '50px'
}, "slow");
div.animate({
fontSize: '7em'
}, "slow");
});
});
</script>
</head>
<body>
<button id="button2">Start Animation2</button>
<button id="button1">Start Animation</button>
<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 style="background:#98bf21;height:100px;width:200px;position:absolute;">HELLO</div>
</body>
</html>
시작 애니메이션
버튼을 클릭 할 때마다 작동합니다. 나는 특정 버튼 (() 함수를 클릭합니다. 내가 ("# 단추 1을") $를 썼다 때문에 그것이 알고 있습니다.하지만 그건
에 영향을주지 않습니다 이유 무엇을 할 수시작 animation2
여러 번의 클릭?
var div = $ ("div"); 모든 div 요소를 선택하고 동일한 div 배열을 반환합니다. 좀 더 구체적으로 만드는지 확인해보십시오 (div.animate 대신 클래스를 추가하거나 div [0] .animate라고 말하면 됨) 문제가 해결됩니다. –
생성하려는 효과는 무엇입니까? 선택기가 어떻게 작동하는지 혼란스러워합니다. –
@KilianStinson 애니메이션 효과 –