在窗口滚动上显示(当前div)的(id)

时间:2015-03-27 05:45:59

标签: jquery html

的index.php

<html>
    <head>
        <script type="text/javascript" src="jquerys/jquery.js"></script>
        <style>
            #parentcontainer div
            {
             height:900px;
             width:600px;
             clear:both;
             border:1px solid red; 
             padding:10px;
             margin:50px 0px; 
            }
        </style>
        <script>
        function showHint() 
            { 
                $('div').load('getdivs.php');  
                $(window).scroll(function()
                {
                    $( ':visible' ).filter('.same').each(function()
                    {
                        alert($(this).attr('id'));
                    });
                });
            }
        </script>
    </head>
    <body onload="showHint()">
        <p>Suggestions: <div class="same2" id="parentcontainer"></div></p>
    </body>
</html>

getdivs.php

<div class="same" id="childcontainer1">  content here 
</div>
<div class="same" id="childcontainer2"> content here 
</div>

当我向下滚动窗口时,无论我在窗口中查看的div如何,我都会收到所有div与(.same)类的提醒。我想要在滚动页面上显示的DIV&S对应的ID。

0 个答案:

没有答案
相关问题