@SeiNakamura (Sei)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

アニメーションによる削除ボタンの表示について

Q&A

Closed

解決したいこと

隣の要素が横に少しスライドすると同時に、非表示の要素を表示。

jQueryのanimate()を使って、矢印をクリックすると削除ボタンが表示されるよう
したいのですが、横方向のoverflow-xが効かず、縦方向にoverflowされ、
下にズレて表示されます。原因がわからず困っています。

該当するソースコード

ソースコードを入力
```<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="stylesheet"
          href="https://unpkg.com/swiper@7/swiper-bundle.min.css"/>
  </head>

  <div>
    <ul>
      <li class="show"><button>go</button></li>
      <li class="list1">隠している</li>
      <li class="list2">こんにちわ</li>
    </ul>
  </div>

  <style>
    ul{
      padding:0;
      overflow-x: auto;
      width:400px;
      height:25px;
    }
    ul li{
      display: inline-block;
    }
    .list1{
      width:300px;
      background-color: green;
      color:white;
    }
    .list2{
      width:300px;
      background-color: red;
      color:white;
      display:none;
    }
    .go {
      width:30px;
    }
  </style>

  <script 
   src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
  </script>
  <script>
    $(function(){
      $("button").on("click",function(){
          $(".list2").animate({
            "width":"toggle",
            "height":['toggle','swing'],
          });
          $("ul").animate({
            "scrollLeft":"300px"
          },500);
      });
    });
  </script>
</html>
0 likes

1Answer

やりたいことのイメージはこのような形でしょうか?

See the Pen Untitled by yotty (@yotty) on CodePen.

変更点としては、ulのdisplayをflexで指定、子要素の幅をmin-widthで指定しています。

0Like

Comments

  1. @SeiNakamura

    Questioner

    仕組みとしては上記の通りです。
    ありがとうございます。

Your answer might help someone💌