开发者

jQuery doesn't know function scrollTop

I want do create a div, which is scrollable in y-direction, but is fixed in x-direction. I already got help with it, here it works: http://jsfiddle.net/Q4dWz/

But somehow it doesn't want to work at home. I've downloaded the latest jquery:

wget -O jquery-1.5.min.js http://code.jquery.com/jquery-1.5.1.min.js

Everytime i call scrollTop I get it says that scrollTop is not a function :( http://gbimg.org/p.php?q=BRYaL I do not understand why it is not a function, and I don't understand, why Firebug says something about jquery 1.2.1 (look at the picture). Here is the code:

160 $(document).ready(function() {
161     $(window).scroll(function(){
162         var $win = $(window);
163         $('#zeit').css('to开发者_开发百科p', 20 - $win.scrollTop());
164     });
165-238 some other functions
238 });


Likely you have a collision with the $ variable in your home environment being set to two jQuery versions, and thus var $win = $(window); is setting $win to a jQuery 1.2.1 object without the required scrollTop function. If you look at the jQuery scrollTop page, you will see that scrollTop was introduced in version 1.2.6.


Make sure you are using the Latest version of jQuery.
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type = text/javascript" ></script>

Also It's a good practice to use parseInt() we doing calculations.

$('#zeit').css('top', parseInt(20-$win.scrollTop()));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜