cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div id="naka">naka</div>
<div id="nishi">nishi</div>
<div id="san">san</div>

            
          
!
            
              #naka , #nishi , #san
  height: 50px
  background-color: red
  
#san.hover
  background-color: purple
            
          
!
            
              //ES5と同じ書き方
var ok1 = function(){
  console.log("ok1");
};

ok1();

//arrow function ()=>を使った書き方
var ok2 = ()=> {
  console.log("ok2");
};

ok2();

//arrow function に引数を用いる書き方
var ok3 = (call) => {
  console.log(call);
};

ok3("ok3");

//引数が一つの場合は()も省略可能
var ok4 = call => {
  console.log(call);
};

ok4("ok4");

//jQueryでCSSを与える書き方
$('#naka').css(
  "background-color","red" 
  );

//ES5でのjQueryの書き方
$('#naka').hover(
  function(){
    $(this).css(
  "background-color","blue");    
  },
  function(){
    $(this).css(
      "background-color","yellow"); 
  }
)

//ES6のarrow functionを使った書き方
//arrow functionを使った場合、thisの挙動が変わるので、thisを修正する。具体的には、ホバーしたjQueryオブジェクトがevent.targetに入っているので、eventを引数として渡して、event.targetにcssを与える。
$('#nishi').hover(
  (event) => {
    $(event.target).css(
  "background-color","green");    
  },
  (event) => {
    $(event.target).css(
      "background-color","red"); 
  }
)

//$().CSSの書き方には2通りある
  //1個だけの場合
  //$('要素').css('プロパティ','値');
  //複数のstyle属性の場合
  //$('要素').css({'プロパティ':'値','プロパティ':'値'});

  //CofeeScriptなら以下でOK
  //$('要素').css 
  //  'プロパティ':'値'
  //  'プロパティ':'値'

//hoverの対象、与えるクラスを変数に入れることでより洗練させた記法
//マウスオーバーした対象に.hoverを与えて、.hoverにCSSでスタイルを記述している
const $hoverTarget = $('#san')
const rolloverClass = 'hover'

$hoverTarget.hover(
  (event) => {
    $(event.target).addClass(rolloverClass);    
  },
  (event) => {
    $(event.target).removeClass(rolloverClass); 
  }
)
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console