Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>Hover Caption</h1>
  <ul>
    <li><img src="https://drive.google.com/uc?export=view&id=1nWqjw9stQjCe5W9S-N1FTiRHokDvMPMZ" alt="picture1_canyon" width="300" height="200"></li>
    <li><img src="https://drive.google.com/uc?export=view&id=1SU0RB2_yQq-vujw8zbelZDYkltKgIdYG" alt="picture2_mountain" width="300" height="200"></li>
  </ul>
</main>
              
            
!

CSS

              
                main {
  width: 320px;
  margin: 0 auto;
 }

h1 {
  font-size: 20px;
  font-weight: light;
  text-align: center;
}

ul {
  padding-left: 10px;
  
}
li {
  list-style-type: none;
  color: #fff;
  width: 300px;
  height: 200px;
  position: relative;
  margin-bottom: 10px;
 }

main div{
  display: none;
	position:absolute;
	width:100%;
	height:100%;
	padding:20px;
	background:rgba(139,194,76,.5);
	top:0;
	left:0;
	box-sizing:border-box;
}

main p{
	position:relative;
	top: 10px;
  padding-top: 48px;
}
              
            
!

JS

              
                $(function(){
  // 1 <li> の最後に <div> を追加する
  $("li").append("<div></div>");

  // 2 追加した <div> 内に画像のキャプションを追加
  $("div").each(function(){
    $(this).html("<p>" + $(this).parent().children("img").attr("alt") + "</p>");
  });

  // 3 画像をマウスオーバーしたときに以下のアクション
  $("li").hover(function(){
    
    // 4 li の子要素 div をフェードイン
    $(this).children("div").stop().fadeIn(300);

    // 5 <p>をCSSで指定していた10pxから0pxへ移動
    $(this).children("div").children("p").stop().animate({"top" : 0}, 300);
  }, function(){
    
    // 6 表示していた div をフェードアウト
    $(this).children("div").stop().fadeOut(300);

    // 7 <p>をtop 0 から 10 へ戻す(下がって見える)
    $(this).children("div").children("p").stop().animate({"top":"10px"}, 300);
  });
});

              
            
!
999px

Console