【问题标题】:How do I get rid of this 'jumpy' jQuery behavior?如何摆脱这种“跳跃”的 jQuery 行为?
【发布时间】:2011-07-26 08:31:43
【问题描述】:

在您按住按钮并按下按钮后,您移动按钮,按钮将再次动画。我试图让它动画起来并保持不动,直到你离开它,然后平滑地动画下来。我确实需要这个才能在 Safari、Firefox 和 IE 中工作。

提前感谢您的帮助、时间和考虑。

这是代码的工作示例。

    <html>
    <head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
    <script type="text/javascript"><!--
    $(document).ready(function() { 
        var navDuration = 500; 
        var navJumpHeight = "90px";

        $('#tabs li').hover(function() {
            $(this).animate({ height : "-="+navJumpHeight }, navDuration);           
        }, function() {
            $(this).animate({ height : "150px" }, navDuration);
        });        
    });
    // --></script>

    <style type="text/css"><!--
    /* CSS Reset */
    html,body,div,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,pre,form,p,blockquote,fieldset,input,hr{margin:0;padding:0;line-height:1em;}
    h1,h2,h3,h4,h5,h6,pre,code,address,caption,cite,code,em,strong,th{font-size:1em;font-weight:normal;font-style:normal;line-height:1em;}
    ul,ol{list-style:none;}
    fieldset,img,hr{border:none;}
    q:before,q:after{content:'';}
    abbr,acronym{border:0;}
    caption,th{text-align:left;}
    table{border-collapse:collapse;border-spacing:0;}
    td {vertical-align:top;}
    html{font-size:100.01%;}
    body{font-size:1em;}
    a img{border: none;}

    body{ font-family:Arial; font-size:10px; font-weight:500; background:#ffffff no-repeat center top; }    
        div.headerblock{ position:absolute; display:table-cell; text-align:center; left:0px; top:0px; width:100%; height:150px; }   
            div.header{ position:relative; width:900px; height:170px; margin-left:auto; margin-right:auto; }
                div.logo        { position:relative; display:table-cell; vertical-align:top; text-align:left; left:0px; top:0px; width:349px; height:170px; float:left; }


        #headerblock #header #tabs { height: 150px; overflow: hidden; padding: 0 10px; left:40; list-style: none; position: relative; filter:alpha(opacity=85); opacity:0.85; }
        #headerblock #header #tabs li, #headerblock #header #tabs li a { width: 100px; position: relative; float: left; }      
        #headerblock #header #tabs li { top: 0 px; margin: 0; background: none; padding: 0; display: block; vertical-align: bottom;}
        #headerblock #header #tabs li a { display: block; color: #ffffff; font-size: 1.7em; text-decoration: none; text-transform: uppercase; height: 150px; line-height: 1.1em}
        #headerblock #header #tabs #tab_about a   { background-color: #ff0000; }
        #headerblock #header #tabs #tab_services a{ background-color: #ffa500; }
        #headerblock #header #tabs #tab_contact a { background-color: #ffff00; }
        #headerblock #header #tabs #tab_learning a{ background-color: #00ff00; }
        #headerblock #header #tabs #tab_clients a { background-color: #0000ff; }
    --></style>
    </head>
    <body>
    <div class="headerblock" id="headerblock">
    <div class="header" id="header">
        <div class="logo">
            &nbsp;
        </div>
        <ul id="tabs">
            <li id="tab_about"><a href="#">&nbsp;<br>Tab 1</a></li>
            <li id="tab_services"><a href="#">&nbsp;<br>Tab 2</a></li>
            <li id="tab_contact"><a href="#">&nbsp;<br>Tab 3</a></li>
            <li id="tab_learning"><a href="#">&nbsp;<br>Tab 4</a></li>
            <li id="tab_clients"><a href="#">&nbsp;<br>Tab 5</a></li>
        </ul>
    </div >
</div>
</body>
</html>

【问题讨论】:

  • 我把它放在一个 jsFiddle 中,这样人们就可以玩它了:jsfiddle.net/PbGaK

标签: jquery html css navigation jquery-animate


【解决方案1】:

lis 中添加 overflow: hidden,因为 jQuery 在动画期间也这样做:http://jsfiddle.net/UJSZq/

#headerblock #header #tabs li { overflow: hidden }

【讨论】:

  • 感谢您的提醒,我真的很感激。
猜你喜欢
  • 1970-01-01
  • 2012-01-15
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-09
相关资源
最近更新 更多