【发布时间】:2021-06-01 08:40:44
【问题描述】:
编辑: 这篇文章已经过编辑,以标记从以前的 jQuery 装置中对纯 JS InteractionObserver 实例的更新,该装置使网站变得非常缓慢。
新问题是我设法让 Rickard 的想法在 Codepen 上进行了一些样式调整(进入时将 .hidden 更改为反向 .visible 类),但对于我的生活,它对我的生活不起作用网站。
具体来说,我认为交叉点没有切换,我同时使用了 console.log 和提示符进行检查,即使逐字复制代码,它们也根本没有启动。
旧代码,用于上下文:
// $(document).ready shorthand
$("section, img, p, h1, h2, h3, h4, span").fadeIn("slow"); });
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll(function() {
/* Check the location of each desired element */
$("section, img, p, h1, h2, h3, h4, span").each(function(i) {
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it in */
if (bottom_of_window > bottom_of_object - 200) {
$(this).animate({ opacity: "1" }, 1000),
$(this).find('.lefttitle').animate({left:"0px"}, 1500);
$(this).find('.righttitle').animate({right:"0px"}, 1500);
}}); }); });
旧 CSS 标题
h2.lefttitle {float:left; text-align:left; left:10px; top:6px;}
h2.righttitle {float:right; text-align:right; right:10px; top:-6px;}
旧 CSS 动画
h3, section.projdescription * {animation:fadeInUp 2s both ease;}
*.visible {animation:fadeInUp 4s both ease;}
@keyframes fadeInUp {
0% {opacity: 0;transform: translate3d(0,10px,0);}
100% {opacity: 1;} }
【问题讨论】:
标签: javascript jquery class animation