最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - applying scroll events on table body - Stack Overflow

programmeradmin0浏览0评论

So I have a table on which I want to capture its scroll event as we capture scroll event on window. I want to capture scroll event when its body scrolls as it as some fixed height and overflow:scroll will be preset:

Fiddle here

Below is what I've tried but with no success:

$('tbody').on('scroll',function(){
    alert('hellow');
});

I am not sure the above code is correct or not. I mean not sure whether there is any event like this for table.

Are there any alternatives to capture scroll events of table body. The main reason being here is fixed table header which works fine in chrome and other browsers but not in IE8 as it jumps and takes time to get fixed again!

So I have a table on which I want to capture its scroll event as we capture scroll event on window. I want to capture scroll event when its body scrolls as it as some fixed height and overflow:scroll will be preset:

Fiddle here

Below is what I've tried but with no success:

$('tbody').on('scroll',function(){
    alert('hellow');
});

I am not sure the above code is correct or not. I mean not sure whether there is any event like this for table.

Are there any alternatives to capture scroll events of table body. The main reason being here is fixed table header which works fine in chrome and other browsers but not in IE8 as it jumps and takes time to get fixed again!

Share Improve this question asked May 28, 2015 at 5:03 Guruprasad J RaoGuruprasad J Rao 29.7k15 gold badges112 silver badges207 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try this, that have to work in IE8:

$('tbody').bind('mousewheel DOMMouseScroll', onWheel);

function onWheel (e){    
    console.log(e);
}

jsFiddle

There is another way to trigger this event. The table from which you want to apply this event, from there itself you can call a JavaScript function.

For example:

<table onscroll="yourFunction()"></table>

and then you can write your code in the yourFunction() function in the script tags.

发布评论

评论列表(0)

  1. 暂无评论