0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

javascriptのサンプル

Posted at
1 / 2

どうもミックです。IT系に転職を考えています。
今は勉強を始めて3ヶ月になります。
今はjavascript,phpを主に勉強しているので今やってることを記事に書いていきます。独学なのでコードは下手くそなのでご了承ください。
udemyのjavascriptのコースを勉強してみた。

index.html
<body>
  <div class="container">
    <div class="panel active" style="background-image: url('https://images.unsplash.com/photo-1624138784614-87fd1b6528f8?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2066&q=80');">
      <h3>Explore The World</h3>
    </div>
    <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1629259634957-e32a0c5c4f47?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1469&q=80');">
      <h3>Explore The World</h3>
    </div>
    <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1598298388182-76077d53c943?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1374&q=80');">
      <h3>Explore The World</h3>
    </div>
    <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1545251142-f32339076e6d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80');">
      <h3>Explore The World</h3>
    </div>
    <div class="panel" style="background-image: url('https://images.unsplash.com/photo-1606503391282-df793e79b892?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80');">
      <h3>Explore The World</h3>
    </div>
  </div>
</body>
style.css
* {
  box-sizing: border-box;
}

body {
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

.container {
  display: flex;
  width: 90vw;
}

.panel {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 80vh;
  border-radius: 50px;
  color: #fff;
  cursor: pointer;
  flex: 0.5;
  margin: 10px;
  position: relative;
  transition: flex 0.7s ease-in;
}

.panel h3 {
  font-size: 24px;
  position: absolute;
  bottom: 20px;
  left: 20px;
  margin: 0;
  opacity: 0;
}

.panel.active {
  flex: 5;
}

.panel.active h3 {
  opacity: 1;
  transition: opacity 0.3s ease-in 0.4s;
}

@media(max-width: 480px) {
  .container {
    width: 100vW;
  }

  .panel:nth-of-type(4),
  .panel:nth-of-type(5) {
    display: none;
  }
}
script.js
const panels = document.querySelectorAll('.panel');

panels.forEach((panel) => {
  panel.addEventListener('click', () => {
    removeActiveClasses()
    panel.classList.add('active')
  })
})

function removeActiveClasses () {
  panels.forEach( panel => {
    panel.classList.remove('active')
  } )
}

画像をクリックすると大きく広がるモーションになっています。

参考文献

https://unsplash.com/
udemy

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?