返回 jQuery 实例与特效代码列表
滚动与布局MIT兼容 jQuery 1.12 / 3.8 / 4.1
滚动渐入动画
卡片元素随滚动进入可见区域时触发由下而上的淡入动画,支持一键重置再次预览。
兼容性说明:全版本兼容(含 slim 精简版)。
在线交互演示(独立沙箱)
$(function () {
var $box = $('#sr-box');
function reveal() {
var bottom = $box.offset().top + $box.height();
$box.find('.sr-card:not(.visible)').each(function () {
if ($(this).offset().top < bottom - 12) $(this).addClass('visible');
});
}
$box.on('scroll', reveal);
$('#sr-reset').on('click', function () {
$box.scrollTop(0).find('.sr-card').removeClass('visible');
setTimeout(reveal, 50);
});
reveal();
});不用 jQuery 怎么写?(现代原生 JS / CSS 替代思路)
使用 IntersectionObserver 监听元素进入视口后添加类名,比 scroll 事件更省电高效。
const io = new IntersectionObserver(entries => {
entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
});
document.querySelectorAll('.reveal').forEach(el => io.observe(el));纯 CSS 辅助工具推荐:打开站内 CSS 动画生成器 →