2014-03-12 74 views
0

我要滾動列表向上和向下,但它不工作如何滾動列表向上和向下的鼠標事件

的jsfiddle:Demo

下面是javascript代碼:

var total = $('ul.item-list li').length; 
    var $totalImgs = $('ul.item-list li'); 

    var thumbHeight = 0; 
    for (x=0; x<total; x++) { 
     thumbHeight = thumbHeight + 41; 
    }; 

    $('ul.item-list').css({height: thumbHeight + 'px'}); 

    $('#Up').hover(function(e){ 
     $('ul.item-list').stop(); 
     posTop = -parseInt($('ul.item-list').css("margin-top")) 
     speed = (posTop) * 4; 
     slideTop = thumbHeight - 50; 
     $('ul.item-list').animate({"margin-top": "80px"}, 800)},function(){$('ul.item-list').stop(); 
    });  

    $('#Down').hover(function(e){ 
     posTop = parseInt($('ul.item-list').css("margin-top")) 
     speed = (thumbHeight + posTop) * 4; 
     slideTop = thumbHeight - 50; 
     $('ul.item-list').stop(); 
     $('ul.item-list').animate({"margin-top": -slideTop + "px"}, speed) 
     },function(){$('ul.item-list').stop(); 
    }); 
+0

什麼具體不工作?你有什麼錯誤嗎? – Andy

+0

請使一個正確的小提琴和發佈它 – Zword

+0

所以你需要所有列表上下滾動只有在淺灰色部分 –

回答

0
  • 使用這個CSS爲你的div - overflow:scroll;
  • 然後它會滾動並且所有列表項都會出現在您的div標記中
+1

我不dont想要使用滾動條 –

+0

+1 @Sumit,有沒有什麼辦法做到這一點,需要滾動而不是滾動條。溢出-y:滾動或自動自帶滾動條 –

+0

因此我使用javascript ...... –

相關問題