如何阻止Jquery下拉滚动页面?

时间:2014-02-27 18:00:10

标签: javascript jquery html css

所以我遇到了一个Jquery下拉列表的问题,如果我向下滚动页面,下拉列表会显示得更远而不是它们应该直接位于按钮下面。

<!doctype html>
<html>
<head>
<title></title>
<link href="/Nexus 5/Website style.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var timeoutID;
$(function(){
    $('.dropdown').mouseenter(function(){
        $('.sublinks').stop(false, true).hide();
        window.clearTimeout(timeoutID);
        var submenu = $(this).parent().next();

        submenu.css({
            position:'absolute',
            top: $(this).offset().top + $(this).height() + 'px',
            left: $(this).offset().left + 'px',
            zIndex:1000
        });

        submenu.stop().slideDown(300);

        submenu.mouseleave(function(){
            $(this).slideUp(300);
        });

        submenu.mouseenter(function(){
            window.clearTimeout(timeoutID);
        });

    });
    $('.dropdown').mouseleave(function(){
        timeoutID = window.setTimeout(function() {$('.sublinks').stop(false, true).slideUp(300);}, 250);
    });
});
</script>
</head>
<body>
<div id="header" style="position: fixed; ">
    <img src="smalllogo.png" style="float:left; width:180px; height:73px;">
      <div class="nav">
            <ul>
            <li><a href="home.html">Home</a></li>
                <li><a  href="Nexus 5/Nexus 5 (home).html" class="dropdown" >Nexus 5</a></li>
                <li class="sublinks">
                    <a href="Nexus 5/Nexus 5 (info).html">Info</a>
                    <a href="Nexus 5/Nexus 5 (root & unlock).html">Root & Unlock</a>
                    <a href="Nexus 5/Nexus 5 (recovery).html">Recoveries</a>
                    <a href="Nexus 5/Nexus 5 (roms).html">ROMs</a>
                    <a href="Nexus 5/Nexus 5 (kernels).html">Kernels</a>
                    <a href="Nexus 5/Nexus 5 (other).html">Other</a>
                </li>
            <li><a href="Galaxy S4/GS4 (home).html" class="dropdown">Galaxy S4</a></li>
            <li class="sublinks">
                <a href="Galaxy S4/GS4 (info).html">Info</a>
                <a href="Galaxy S4/GS4 (root & unlock).html">Root & Unlock</a>
                <a href="Galaxy S4/GS4 (recovery).html">Recoveries</a>
                <a href="Galaxy S4/GS4 (roms).html">ROMs</a>
                <a href="Galaxy S4/GS4 (other).html">Other</a>
            </li>
            <li><a href="../about.html">About</a></li>
            </ul>
        </div>
  </div>

Normal

然后当滚动并向下滚动时,jquery链接就会向下移动。

可以从androiddevelopmentdepot.com

直播查看

1 个答案:

答案 0 :(得分:3)

我无法理解为什么你要计算它的最高位置。修复顶部,可以解决您的问题吗?

试试这个:

submenu.css({
    position:'absolute',
    top: 75,
    left: $(this).offset().left + 'px',
    zIndex:1000
});