<Select> widget with infinite scroll dropdown

后端 未结 2 791
逝去的感伤
逝去的感伤 2020-12-18 07:17

At my page i have about 20 common html select widgets. For example:


                        
    
提交评论

  • 2020-12-18 07:39

    I have provided a set of working example of combo-box using jQuery UI selectmenu. I have used basic JSON source for ajax request, please work on this part yourself.

    $(".ajax-combo").selectmenu({
      "width": "100px",
    });
    $(".ajax-combo").selectmenu("menuWidget").addClass("make-scrolling");
    $(".ajax-combo").selectmenu("menuWidget").scroll(function(e) {
      if (e.currentTarget.scrollHeight - 10 < e.currentTarget.scrollTop + $(e.currentTarget).height()) {
        var curTar = e.currentTarget;
        var lastTop = curTar.scrollTop;
        $.getJSON("http://echo.jsontest.com/10/test/20/rest/30/best/40/vest/50/fest", function(data) {
          $.each(data, function(key, val) {
            $(".ajax-combo").append("<option value='" + key + "'>" + val + "</option>");
          });
          $(".ajax-combo").selectmenu("refresh");
          curTar.scrollTop = lastTop;
        });
      }
    });
    .make-scrolling {
      overflow-y: scroll;
      height: 150px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
    
    <select class="ajax-combo">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>1</option>
      <option>2</option>
      <option>3</option>
    </select>

    0 讨论(0)
  • 提交回复
    热议问题