在通过ajax加载内容后,如何在div工作顶部创建水平滚动条

时间:2015-09-20 19:31:41

标签: javascript jquery html css ajax

HTML代码

   <div  id="scrollidout"  style="overflow: auto; overflow-y: hidden; ">
    <div id="scrollidin" style="padding-top: 1px; height: 20px; width: 1000px">&nbsp;</div>
</div>
<div class="resultcontent" style="overflow: auto; overflow-y: hidden; " id="resultcontent" >

  SEARCH RESULTS HERE

  <div id="scrollidin12" style="padding-top: 1px; height: 190px; width: 3200px">
    klklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklk
    lklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklkklklklklk
  </div>

</div>

JAVASCRIPT CODE

 $(function(){


   $('#scrollidout').on('scroll', function(){
        $('#resultcontent')
            .scrollLeft($('#scrollidout').scrollLeft());
    });

    $('#resultcontent').on('scroll', function(){
        $('#scrollidout')
            .scrollLeft($('#resultcontent').scrollLeft());
    });
  });

加载时首先它在整个页面工作时起作用 但是当我改变div的内容时,#resultcontent&#34;使用Ajax,我无法使用顶部滚动条再次滚动div。我怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

对你有帮助吗? https://developer.mozilla.org/fr/docs/Web/CSS/overflow

使用overflow : scroll放置一个类以强制显示滚动条。