2017-06-27 10 views
0

私はフィドルexample

NOTEを作成しました:私は、サードパーティ製のプラグインをお勧めしませんfiddle.Soに示すように、カスタムのドロップダウンを使用しています私のアプリのための小さなプラグインを開発しています。

$(function() { 
 
    $('select').select2(); 
 
    $('#name').on('click', function() { 
 
    $('.dropdown').show(); 
 
    }); 
 

 
    $('#name').on('blur', function() { 
 
    $('.dropdown').hide(); 
 
    }); 
 
});
.modal-body { 
 
    height: 250px; 
 
    overflow-y: auto; 
 
} 
 

 
.wrapper { 
 
    position: relative; 
 
} 
 

 
.dropdown { 
 
    width: 200px; 
 
    height: 200px; 
 
    overflow-y: scroll; 
 
    position: absolute; 
 
    display: none; 
 
    z-index: 2000px; 
 
} 
 

 
.dropdown li { 
 
    list-style: none; 
 
} 
 

 
.select2 { 
 
    float: right; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 

 

 
<!-- Button trigger modal --> 
 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"> 
 
     Launch demo modal 
 
    </button> 
 

 
<!-- Modal --> 
 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
     <div class="modal-body"> 
 
     <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
      It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with 
 
      desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
     </p> 
 
     <div class="wrapper"> 
 
      <input type="text" id="name" /> 
 
      <ul class="dropdown"> 
 
      <li>a</li> 
 
      <li>b</li> 
 
      <li>c</li> 
 
      <li>d</li> 
 
      <li>e</li> 
 
      <li>f</li> 
 
      <li>g</li> 
 
      <li>h</li> 
 
      <li>i</li> 
 
      <li>j</li> 
 
      <li>k</li> 
 
      <li>l</li> 
 
      <li>m</li> 
 
      </ul> 
 
     </div> 
 
     <select> 
 
       <option>a</option> 
 
       <option>b</option> 
 
       <option>c</option> 
 
       <option>d</option> 
 
       <option>e</option> 
 
       <option>f</option> 
 
       <option>g</option> 
 
       <option>h</option> 
 
       <option>i</option> 
 
       <option>j</option> 
 
      </select> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

+0

[How To Ask](https://stackoverflow.com/help/how-to-ask)に慣れてください。あなたの質問には質問は含まれておらず、質問自体には最小で完全で検証可能な例*は含まれていません。JSFiddleリンクは補足として役立ちますが、質問は外部リソースに依存することなく完全に独立して立つことができるはずです。 – Santi

+1

@サンティ私は自分の質問を少し改善しました。実際の例がうまく説明できるので、私はフィドルを追加しました。 – zerocon

+1

さて、閉会投票を削除しました。つまり、StackOverflowにはスニペットボタンがあり、JSFiddleのように実行可能なスニペットをあなたの質問に埋め込むことができ、[MCVE Requirement](https://stackoverflow.com/help/mcve)を満たしているので、あなたの質問はそうではありませんリスクの閉鎖。ボタンは次のようになります: '[<>]'。スニペットとして実行するようにあなたの質問を編集します - これは非常に便利なツールです。 – Santi

答えて

0

ドロップダウンを開くたびに、モーダル本体の底部に近い、その下部にはアクセスできなくなります。そのため、ブラウザが親のheightを自動的に調整して、ユーザーが親をスクロールしてドロップダウンの内容にアクセスできるようにします。

これは、ドロップダウンが、モダル本体を下側または右側にオーバーフローし、左側または上側にオーバーフローしない場合にのみ発生します。これはデフォルト動作です。

これを修正するには、ドロップダウンをドロップダウンにするか、または親に十分なボトムパッドを追加して、ドロップダウンを開いても親の高さに影響を与えないようにします。


それとも、あなたはselect2が何を行うことができます:

  • <select>要素を非表示(またはインラインを持って何でも)、
  • がに関して<body>と位置/サイズにコンテナーを追加ビューポート、現在のスクロール、現在のドロップダウン位置、
  • 利用可能なスペース内のオプションをレンダリングします。
  • hide <body>ユーザーが選択を選択したときの子要素
  • インライン要素とそれに関連付けられたフォーム要素を調整して、ユーザーの選択を反映させます。
  • ドロップダウンが再び開かれるときはいつでも重要な要素は、すべてが<body>の直接の子(.select2-container - SELECT2プラグインの開始時に添加される)内部で起こることがあり、その位置を再調整

<body>子を再利用するため、お子様は.modal-bodyではありません。

関連する問題