English 中文(简体)
jjQuery: 当用户滚滚过一个点时, 幻灯片页眉头
原标题:jQuery: slide header when user scrolls past a point
  • 时间:2012-05-25 10:13:39
  •  标签:
  • jquery

我有以下jQuery 代码:

if($(window).scrollTop()>=220) {
                    $( #header nav ).slideUp( fast ).removeClass( fixed );
                } else {
                    $( #header nav ).addClass( fixed ).slideDown( fast );
                }

当用户滚动到页面下方超过220 像素时,页眉会得到类类固定,然后滑倒。当用户再次向上移动时,页眉会向上滑动,然后将其类固定删除。用户将永远不会看到页眉回到原来的位置,就像在屏幕上大约180 像素一样。

然而,问题在于,当用户卷轴没有我想要的那么好的时候,它会一次又一次地使幻灯片滑动。我看过停止方法,但停止当前的动画也不是我的需要。对于如何解决这个问题有什么想法吗?

上述代码是一个被称为函数的函数 :

$(window).scroll(function() {
                    fixedHeader();
                });
问题回答

您想要更改 if( $( window).scrollTop () & gt; =220) \ {/ code> 行以检查用户是否已从 0-220 过渡到 220 + 或逆向, 而不是使用每一个滚轮 。

具有许多评论的教程的范例是

这样做解决了问题:

if(!$( #header nav ).hasClass( fixed )) {
                        $( #header nav ).addClass( fixed ).slideDown( fast );
                    }

此资源也许可以帮助您 : < a href=" http:// return- true.com/2010/04/scroll- activated- sliide- down- header- with - jquery/" rel=" no follow" @ em> scroll 激活幻灯片下游

$(function() {
    var bar = $( #headerSlideContainer );
    var top = bar.css( top );
    $(window).scroll(function() {
        if($(this).scrollTop() > 50) {
            bar.stop().animate({ top  :  0px }, 500);
        } else {
            bar.stop().animate({ top  : top}, 500);
        }
    });
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...