0

I have many tr in the visible area where it generates a scrollbar, tr each has its own id, how do I know if it is in the visible area of the scrollbar, and if not how do I place it in the visible area using Jquery ?

<tr align="center" id="100"><td><a> info </a></td></tr>
<tr align="center" id="101"><td><a> info </a></td></tr>
<tr align="center" id="102"><td><a> info </a></td></tr>
<tr align="center" id="103"><td><a> info </a></td></tr>
<tr align="center" id="104"><td><a> info </a></td></tr>
<tr align="center" id="105"><td><a> info </a></td></tr>
<tr align="center" id="106"><td><a> info </a></td></tr>
<tr align="center" id="107"><td><a> info </a></td></tr>
4

2 回答 2

1

http://jsfiddle.net/DerekL/b5Bwx/

一种快速简便的方法:

$("div").on("scroll", function(){
   var y = $("#target").offset().top;
    if(y < this.offsetHeight && y > -$("target").height(){
        $("span").append("Visible");
    }
});

或者这个:http: //jsfiddle.net/DerekL/Lxsmt/

于 2013-04-18T21:10:28.577 回答
0

要确定它们是否在视口中,您需要使用一个函数来计算它。像这样的东西会起作用(不需要jQuery):

function isElementInViewport(el) {
    var rect = el.getBoundingClientRect();

    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
        rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
        );
}

然后,您可以从类似的链接滚动到它们<a href="#101">Go To Row 1</a>

于 2013-04-18T21:09:04.287 回答