.animate(): Thực hiện một hình ảnh động (animate) tùy chỉnh của một tập hợp các thuộc tính css.
Đã được thêm vào từ phiên bản 1.0
.animate(Thuộc tính,Tốc độ,'easing',function(){})
Thuộc tính:
Tốc độ có thể bằng số hoặc bằng chữ: slow, fast (mặc đinh 400).
Easing có thể sử dụng swing hoặc linear (mặc định swing).
$('.test').animate({
opacity: 0.25,
left: "+=50",
height: "toggle"
}, 5000, 'swing', function() {
// Animation complete.
});;
Các giá trị của options:
$('img').animate({
width: 'toggle',
height: 'toggle'
}, {
duration: 5000,
specialEasing: {
width: 'linear',
height: 'linear'
},
complete: function() {
$(this).after("Animation Complete");
}
});
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
button {
margin: 10px;
}
img {
position: relative;
left: 10px;
}
</style>
<script>
$(function(){
$('button').click(function() {
$('img').animate({
opacity: 0.25,
left: '+=50',
height: 'toggle'
},2000, function() {
$('button').text("Click tiếp để thấy hiệu ứng");
});
});
});
</script>
</head>
<body>
<p><button>Click here</button></p>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg" alt="" width="129" height="129">
</body>
</html>
Hiển thị trình duyệt:
Click vào button để xem hiệu ứng animate.
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
button {
margin: 10px;
}
img {
position: relative;
left: 10px;
}
</style>
<script>
$(function(){
$('button').click(function() {
$('img').animate({
opacity: 0.25,
left: '+=50',
height: 'toggle'
},2000, function() {
$('button').text("Click tiếp để thấy hiệu ứng");
});
});
});
</script>
</head>
<body>
<p><button>Click here</button></p>
<img src="https://hoclaptrinh.vn/themes/client/img/code-screen.jpg" alt="" width="129" height="129">
</body>
</html>
Hiển thị trình duyệt:
Click vào button để xem hiệu ứng animate.
Unpublished comment
Viết câu trả lời