cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - 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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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="wrapper">
  <img id="img" src="">
  <div id="info">
    <p id="name"></p>
    <p id="email"></p>
    <p id="cell"></p>
  </div>
  <button id="gain" class="button">Generator</button>
</div>
            
          
!
            
              #wrapper {
  margin: 0 auto;
}

img {
  float: left;
  display: block;
  margin: 0 auto;
  margin-bottom: 10px;
  border: 3px solid #fff;
  box-shadow: 1px 2px 4px #000;
  width: 200px;
  height: 200px;
}

#name {
  padding-top: 30px;
  font-size: 2.2em;
  font-weight: bold;
}

#email {
  padding-top: 17px;
  font-size: 1em;
}

#info {
  float: left;
  padding: 15px 5px;
  width: 250px;
  height: 177px;
  margin: auto;
  background: #c3609e;
  color: #fff;
  text-align: center;
}

p {
  margin: 0px;
}

//btn
$color: #e970e5;

@keyframes sheen {
  0% {
    transform: skewY(-45deg) translateX(0);
  }
  100% {
    transform: skewY(-45deg) translateX(12.5em);
  }
}

.button {
  cursor: pointer;
  width: 220px;
  border: none;
  margin-top: 80px;
  padding: 48px 0px;
  text-align: center;
  text-decoration: none;
  color: #000;
  font-weight: bold;
  font-size: 24px;
  transition: all 0.2s ease-in-out;
  position: relative;
  overflow: hidden;
  &:before {
    content: "";
    background-color: rgba(255,255,255,0.5);
    height: 100%;
    width: 3.5em;
    position: absolute;
    top: 0;
    left: -4.5em;
    transform: skewX(-45deg) translateX(0);
  }
  &:hover {
    background: $color;
    color: #fff;
    border-bottom: 1px solid darken($color, 10%);
    &:before {
      transform: skewX(-45deg) translateX(13.5em);
     transition: all 0.6s ease-in-out;
    }
  }
  &:focus {
    outline: none;
  }
}
            
          
!
            
              var gain = document.getElementById('gain');

// gainButton ClickでAPI読み込み
gain.addEventListener('click', function() {
  var script = document.createElement('script');
  script.src = "https://randomuser.me/api?callback=jsonData";
  document.body.appendChild(script);
  document.body.removeChild(script);
})

//コールバックされた「jsonData」を読み込み
function jsonData(data) {
  //取得されるデータをみるとたくさんは居ているのがわかる。
  console.log(data);

  var result = data.results[0];
  var name = document.getElementById('name');
  var email = document.getElementById('email');
  var img = document.getElementById('img');
  var cell = document.getElementById('cell');
  
  //取得した各データをHTML要素に代入する。
  //html elementのあとをメソッドチェーンみたいにすることで、プロパティのバリューを指定できる。
  img.src = result.picture.large;
  name.textContent = result.name.first;
  email.textContent = result.email;
  cell.textContent = result.cell;
}
            
          
!
999px
Loading ..................

Console