繁体   English   中英

使当前div在视口中可见

[英]get current div visible in viewport

我对jQuery还是很陌生,我正在尝试实现无限滚动,因此一旦到达页面末尾,便能够触发对后端的ajax调用。 我还想知道当前div在视口中可见,以便我也可以发出ajax调用。 提示我有6格

<div id="test">
            Some content here
<div>
    <div id="test1">
        more content here
    </div>
    <div id="test2">
        more content here again
    </div>

如果光标向上滚动到第二个div时,我想发出ajax调用,第三个div和第一个div也一样。 我对此太天真,所以我可能问一个愚蠢的问题,但请原谅我。

尝试这个

$("div").mouseover(function(){
    $id = $(this).attr("id"); //retrieve id, e.g. test, test1, test2, etc
    //if ajax call by switch case
    switch($id){
        case "test":
            //ajax code
            break;

        case "test1":
            //ajax code
            break;
    }
    //or directly ajax
    $.ajax({...});
    //or so on
});

希望这对您有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM