「jQuery」hide()で引数にミリ秒を指定するサンプル

環境
Google Chrome 103.0.5060.134
jquery 3.6.0

構文
対象要素.hide( ミリ秒);
引数に数値(ミリ秒単位)を与えることで、指定時間内に合わせて要素が消えるようになります。

使用例
3秒間かけてdiv要素を非表示にします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div>テキスト222228888</div>
<button>動作</button>
<script>
$('button').click(function() {
$('div').hide(3000);
})
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </head> <body> <div>テキスト222228888</div> <button>動作</button> <script> $('button').click(function() { $('div').hide(3000); }) </script> </body> </html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>

<div>テキスト222228888</div>
<button>動作</button>

<script>
    $('button').click(function() {
        $('div').hide(3000);
    })
</script>
</body>
</html>

実行結果
動作ボタンをクリックした時に「hide(3000)」を実行します。画面に3秒をかけてdiv要素を非表示にします。

jQuery

Posted by arkgame