window - 在窗口滚动上移动元素

标签 window scrolltop

你会在这个 JsFiddle 中看到 https://jsfiddle.net/xpvt214o/402281/在窗口滚动上有一个图像在另一个图像中滚动。
如何修改下面的内容,使其在遇到该元素之前不会开始滚动(在所有 br 标签之后)?
我试过抵消它,但没有取得任何进展。

如果它只是滚动得慢很多也没关系。

jQuery(document).ready(
function() {

var $w = $(window);
var $d = $('.oh');

$(window).scroll(function(event) {
  var st = $w.scrollTop();

  _x = st;

  lastScrollTop = st;

  $d.css('bottom', _x);      

});

});

这是我试图实现的一个例子 https://www.sketchapp.com/

最佳答案

我发现这符合我的要求

https://codepen.io/JTParrett/pen/BkDie

$.fn.moveIt = function(){
var $window = $(window);
var instances = [];

$(this).each(function(){
instances.push(new moveItItem($(this)));
});

window.addEventListener('scroll', function(){
var scrollTop = $window.scrollTop();
instances.forEach(function(inst){
  inst.update(scrollTop);
});
}, {passive: true});
}

var moveItItem = function(el){
this.el = $(el);
this.speed = parseInt(this.el.attr('data-scroll-speed'));
};

moveItItem.prototype.update = function(scrollTop){
  this.el.css('transform', 'translateY(' + -(scrollTop / this.speed) + 
'px)');
};

// Initialization
$(function(){
  $('[data-scroll-speed]').moveIt();
});

关于window - 在窗口滚动上移动元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51303260/

相关文章:

javascript - React Native 确定用户是否位于屏幕顶部

kendo-ui - 如何在剑道用户界面中以关闭 Action 销毁剑道弹出窗口

wpf - Window.SourceInitialized 事件何时引发

javascript - 在 Angular 的 window 对象中存储值有什么好处?

jquery - 如何找到相对于其父元素的元素位置以使其滚动可见

jQuery的scrollTop有点跳动

c - 链接到 ntdll.lib 并调用 ntdll.dll 中的函数

macos - Mac 应用程序窗口停止更新

ios - 点击 UITabBarItem 像 Instagram 和 Twitter 一样滚动到顶部

javascript - jQuery ScrollTop 加速