如何在鼠标事件上上下滚动列表

时间:2014-03-12 11:41:58

标签: javascript jquery html css

我想向上和向下滚动列表,但它无法正常工作

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();
    });

1 个答案:

答案 0 :(得分:0)

  • 将此CSS用于div - overflow:scroll;
  • 然后它会滚动,所有列表项都会出现在你的div标签