Định nghĩa và sử dụng .fadeIn() trong jQuery

.fadeIn(): Hiển thị các thành phần phù hợp với hiệu ứng rõ dần (fade in).

Cấu trúc .fadeIn() trong jQuery

Đã được thêm vào từ phiên bản 1.0

.fadeIn(Độ bền)

Độ bền có thể bằng số hoặc bằng chữ: slow, fast.

$('p').fadeIn(300);
$('p').fadeIn('fast');
.fadeIn(Độ bền,function(){...})
Độ bền có thể bằng số hoặc bằng chữ: slow, fast.

$('p').fadeIn(300,function(){
    $('span').fadeIn(100);
});

Đã được thêm vào từ phiên bản 1.4.3

.fadeIn(Độ bền,'easing',function(){...})

Độ bền có thể bằng số hoặc bằng chữ: slow, fast.

Easing có thể sử dụng swing hoặc linear

$('p').fadeIn(300,'swing',function(){
    $('span').fadeIn(100);
});

.fadeIn(Độ bền)

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>
div {
    background-color: blue;
    display: none;
    float: left;
    margin-right: 20px;
    height: 100px;
    width: 100px;
}
p {
    clear: both;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('.test03').fadeIn(2000);
        $('.test02').fadeIn('slow');
        $('.test01').fadeIn();
    });
});
</script>
</head>

<body>
<p><button>Click</button></p>
<div class="test03">fadeIn(2000)</div>
<div class="test02">fadeIn('slow')</div>
<div class="test01">fadeIn()</div>
</body>
</html>

Hiển thị trình duyệt:

Click vào button để thấy hiệu ứng.

.fadeIn(Độ bền,function(){...})

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>
div {
    background-color: blue;
    display: none;
    float: left;
    margin-right: 20px;
    height: 100px;
    width: 100px;
}
p {
    clear: both;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('div').fadeIn(2000,function(){
            $(this).css('background-color','red');
        });
    });
});
</script>
</head>

<body>
<p><button>Click</button></p>
<div>Thành phần div</div>
</body>
</html>

Hiển thị trình duyệt:

Click vào button để thấy hiệu ứng, sau khi hoàn thành hiệu ứng sẽ hiển thị nội dung bên trong function.

.fadeIn(Độ bền,'easing',function(){...})

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>
div {
    background-color: blue;
    display: none;
    float: left;
    margin-right: 20px;
    height: 100px;
    width: 100px;
}
p {
    clear: both;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('.swing').fadeIn(2000,'swing',function(){
            $(this).css('background-color','red');
        });

        $('.linear').fadeIn(2000,'linear',function(){
            $(this).css('background-color','red');
        });
    });
});
</script>
</head>

<body>
<p><button>Click</button></p>
<div class="swing">fadeIn swing</div>
<div class="linear">fadeIn linear</div>
</body>
</html>

Hiển thị trình duyệt:

Click vào button để thấy hiệu ứng, sau khi hoàn thành hiệu ứng sẽ hiển thị nội dung bên trong function.

Viết câu trả lời

Drop Images

0 Bình luận