admin管理员组文章数量:1287649
I have an element on my page absolutely positioned.
Im trying to write a snippet of jQuery to make that element scroll at a slower rate than the rest of the elements on the page.
I've written this so far but cannot seem to get it too work at all. Has anybody experience with this and if so would you care explaining?
$(document).ready(function() {
$window = $(window);
$('.twit-bird').css({
'top' : -($('window')/3)+"px"
});
});
I've also tried to add an anchor, a fixed div at the top of my window to work out the calcs from that with no luck...
also tried this
$(document).ready(function() {
// Cache the Window object
windowScroll = $(this).scrollTop();
$(window).scroll(function() {
$('.twit-bird').css({
'top' : -(windowScroll/3)+"px"
});
});
});
I have an element on my page absolutely positioned.
Im trying to write a snippet of jQuery to make that element scroll at a slower rate than the rest of the elements on the page.
I've written this so far but cannot seem to get it too work at all. Has anybody experience with this and if so would you care explaining?
$(document).ready(function() {
$window = $(window);
$('.twit-bird').css({
'top' : -($('window')/3)+"px"
});
});
I've also tried to add an anchor, a fixed div at the top of my window to work out the calcs from that with no luck...
also tried this
$(document).ready(function() {
// Cache the Window object
windowScroll = $(this).scrollTop();
$(window).scroll(function() {
$('.twit-bird').css({
'top' : -(windowScroll/3)+"px"
});
});
});
Share
Improve this question
edited Jan 5, 2021 at 20:51
Timothy Aaron
3,07821 silver badges22 bronze badges
asked Feb 10, 2012 at 22:15
LiamLiam
9,85540 gold badges114 silver badges214 bronze badges
2 Answers
Reset to default 7I can point you in the right direction. You need your $('.twit-bird').css()
to get called every time the window is scrolled. Also you forgot .scrollTop()
, and don't quote window
(or, even better just use this
) ...
$(window).scroll(function () {
$('.twit-bird').css({
'top' : -($(this).scrollTop()/3)+"px"
});
});
Here is a very very good tutorial for parallax scrolling. It made me understanding how it really works.
本文标签: javascriptMake element scroll slower (Parallax)Stack Overflow
版权声明:本文标题:javascript - Make element scroll slower (Parallax) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741317353a2371995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论