2 回答
TA贡献1827条经验 获得超7个赞
我找到了解决方案。对于任何感兴趣的人,我是这样解决的:
window.addEventListener('scroll', throttle(check_if_in_view, 220), {
capture: true,
passive: true
});
var $animation_elements = $('.zoom-images');
var $window = $(window);
function check_if_in_view() {
var window_height = $window.height();
var window_top_position = $window.scrollTop();
var window_bottom_position = (window_top_position + window_height);
$.each($animation_elements, function() {
var $element = $(this);
var $zoom = $(this).children('img.zoom');
var element_height = $element.outerHeight();
var element_top_position = $element.offset().top;
var element_bottom_position = (element_top_position + element_height);
if ((element_bottom_position >= window_top_position) &&
(element_top_position <= window_bottom_position)) {
requestAnimationFrame( function() {
$zoom.addClass('is-zooming');
});
} else {
requestAnimationFrame( function() {
$zoom.removeClass('is-zooming');
});
}
});
};
添加回答
举报