你会在这个 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/