如何使用J查询自动滚动旋转

时间:2015-07-01 09:26:08

标签: javascript jquery asp.net

数字应自动旋转。完成一个循环后,它应该从上一个循环开始



$(function() {
      var interval = setInterval(function() {
        if ($("#div1").scrollTop() != $('#div1')[0].scrollHeight) {
          $("#div1").scrollTop($("#div1").scrollTop() + 10);
        } else {
          clearInterval(interval);
        }
      }, 1000);
});

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id="div1" style="height:60px;width:100%;border:1px solid #ccc;overflow:auto">>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

    /array to store IDs of our tabs
      var tabs = [];
     //index for array
     var ind = 0;
    //store setInterval reference
      var inter;

    //change tab and highlight current tab title
    function change(stringref){
   //hide the other tabs
       jQuery('.tab:not(#' + stringref + ')').hide();
  //show proper tab, catch IE6 bug
if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")
    jQuery('.tab#' + stringref).show();
else 
    jQuery('.tab#' + stringref).fadeIn();
//clear highlight from previous tab title
jQuery('.htabs a:not(#' + stringref + 't)').removeClass('active');
//highlight currenttab title
jQuery('.htabs a[href=#' + stringref + ']').addClass('active');
}
   function next(){
   //call change to display next tab
   change(tabs[ind++]);
//if it's the last tab, clear the index
if(ind >= tabs.length)
    ind = 0;
  }
  jQuery(document).ready(function(){
//store all tabs in array
jQuery(".tab").map(function(){
    tabs[ind++] = jQuery(this).attr("id");
})
//set index to next element to fade
ind = 1;
//initialize tabs, display the current tab
jQuery(".tab:not(:first)").hide();
jQuery(".tab:first").show();
//highlight the current tab title
jQuery('#' + tabs[0] + 't').addClass('active');
//handler for clicking on tabs
jQuery(".htabs a").click(function(){

    //if tab is clicked, stop rotating 
    clearInterval(inter);
    //store reference to clicked tab
    stringref = jQuery(this).attr("href").split('#')[1];
    //display referenced tab
    change(stringref);
    return false;
});
//start rotating tabs
inter = setInterval("next()", 7500);

});