LoginSignup
0
0

More than 3 years have passed since last update.

jQuery ① (自分用)

Last updated at Posted at 2020-02-08

準備

①今回はemmet記法を使い、時短

VSCode で index.html内に

! + エンター

スクリーンショット 2020-02-08 18.26.57.png

↓一発で以下になる

スクリーンショット 2020-02-08 18.24.18.png

②jQueryを読み込む為の追記

Google Developers
head内に追記する

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

ここからjQueryを実践

【jQueryはオブジェクト化する】

$('セレクタ').メソッド();

hoverの例

main.js
$(function() {
  $('#menu').hover(
    function() {
    //hoverの第一引数としてfadeIn
    $('.text').fadeIn();
    },
    //hoverの第二引数としてfadeOut
    function() {
      $('.text').fadeOut('slow');  //今回はslow
  }
  );

});
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>仮サイトをJQueryで作成</title>
  <link rel="stylesheet" href="css/styles.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
  <div id ="menu">
    <h1 class="title">仮サイトを作成</h1>
    <p class="text">
      今回はJQueryで仮サイトを作成します。
    </p>
  </div>

  <script src="main.js"></script>
</body>
</html>
styles.css
.text {
  display: none;
}

<検証ツールで確認>
hover時
スクリーンショット 2020-02-08 19.20.08.png

hover無し
スクリーンショット 2020-02-08 19.21.06.png

続→ jQuery 仮サイト作成のbase

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0