2016-08-02 48 views
0

看起来像一个被广泛覆盖的主题,但我仍然无法得到它在给定的情况下工作。我正在为我的表实现箭头向上/向下处理程序,以下是我的代码:Jquery/JS中的触发器窗口滚动

$(document).on('keydown', 'tr input', function (e) 
{ 
    switch(e.which) 
    { 
     // ... 
     case 40: // down 
      e.preventDefault(); 
      target = some_element;  
      if ($(window).height() - target.offset().top < SCROLL_DELTA) 
      { 
       $(window).scroll(); // I thought this would make my window  
            // scroll down one step, but this does not happen 
      } 
      // .... 

只是为了阐明。我有一张桌子,里面有td的输入。当用户按下箭头键时,他会浏览输入。浏览器不会自动向下滚动,因为用户到达屏幕视图范围之外的区域,我必须自己去打扰它。所以我的目标是当用户到达靠近页面底部的输入时滚动一步。所以问题是,我应该写什么而不是$(window).scroll()来使它工作?

+1

嗨哥做,读到这里http://www.w3schools.com/jsref/met_win_scrollto.asp –

+0

哇,太好了。非常简单,非常感谢你,阿仁_ –

回答

1

您可以window.scrollTo(x,y)功能

了解更多详情阅读MDN