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

.slideDown(): Hiển thị các thành phần phù hợp với hiệu ứng chuyển động trượt (slide).

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

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

.slideDown(Độ bền)

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

$('p').slideDown(300);
$('p').slideDown(fast);
.slideDown(Độ bền,function(){...})

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

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

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

.slideDown(Độ bền,'easing')

Độ 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').slideDown(300,'swing');
.slideDown(Độ 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').slideDown(300,'swing',function(){
    $('span').fadeIn(100);
});

.slideDown(Độ 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: 150px;
}
p {
    clear: both;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('.test03').slideDown(2000);
        $('.test02').slideDown('slow');
    });
});
</script>
</head>

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

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

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

.slideDown(Độ 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: 150px;
}
p {
    clear: both;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('div').slideDown(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.

.slideDown(Độ bền,'easing')

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: 150px;
}
p {
    clear: both;
}
.visible {
    background-color: red;
    display: block!important;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('.swing').slideDown(2000,'swing');

        $('.linear').slideDown(2000,'linear');
    });
});
</script>
</head>

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

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

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

.slideDown(Độ 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: 150px;
}
p {
    clear: both;
}
.visible {
    background-color: red;
    display: block!important;
}
</style>
<script>
$(function(){
    $('button').click(function(){
        $('.swing').slideDown(2000,'swing',function(){
            $(this).addClass('visible').text('Nội dung mới');
        });

        $('.linear').slideDown(2000,'linear',function(){
            $(this).addClass('visible').text('Nội dung mới');
        });
    });
});
</script>
</head>

<body>
<p><button>Click</button></p>
<div class="swing">slideDown swing</div>
<div class="linear">slideDown 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