如何在使用jquery滚动一个位后停止一个div [英] How to halt a div after scrolling a bit using jquery

查看:107
本文介绍了如何在使用jquery滚动一个位后停止一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个div垂直固定在一个定义的滚动层。我试过这个:

I want a div to be vertically fixed at a defined scrolllevel. I tried this:

HTML:

<div id='something'>Something! </div>

CSS:

#something { 
    position:relative;
}

JQuery:

$(window).scroll(function(){
    if ($window.scrollTop() > 50){
        $("#something").css({"top": ($(window).scrollTop()) -50 + "px"});
    }
});

这是一个演示: http://jsfiddle.net/1Blerk/3jacz/4/
(#something应该像#headerMenu一样,但在一些滚动后)

Here is a demo: http://jsfiddle.net/1Blerk/3jacz/4/ (#something should do the same as #headerMenu, but after some scrolling)

我不想改变位置来修复!

And i do not want to change position to be fixed!

我不太熟悉JQuery,所以我猜猜它只是一些parantheses或选择器或...

I am not really familiar with JQuery, so i guess it is just some parantheses or a selector or...

提前感谢!

推荐答案

您忘了将 $(window)包裹在括号中。

You forgot to wrap $(window) in parenthesis.

a href =http://jsfiddle.net/BG7U8/ =nofollow> FIDDLE

FIDDLE

这篇关于如何在使用jquery滚动一个位后停止一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆