javascript - 如何编辑 jQuery 动画以显示在元素中间?

标签 javascript jquery css animation jquery-animate

I am using this code from JS Fiddle to create a fade animation with elements on a web page.现在,一旦整个元素在窗口中可见,该元素就会淡入。有什么方法可以编辑它以便我可以更快地触发淡入淡出动画吗?理想情况下,当只有一半元素而不是整个元素可见时,将触发淡入淡出动画。

这是触发此动画的 JavaScript:

/* every time the window is scrolled ... */
 $(window).scroll( function(){
    /* check the location of each desired element */
    $('.fade-in').each( function(i){
        var bottom_of_object = $(this).offset().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 ){
            $(this).animate({'opacity':'1'},600);
        }
    });
});
});

最佳答案

bottom_of_object 值更改为小于原始高度的值

var bottom_of_object = $(this).offset().top + $(this).outerHeight() / 3; //we dived by 3 here at the end.

关于javascript - 如何编辑 jQuery 动画以显示在元素中间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402990/

相关文章:

javascript - 一键切换多个类别

html - 如何更改输入文件按钮大小?

javascript - 如何在数据表中将过滤类型从 LIKE 更改为 EQUAL

javascript - 将按钮的实例传递给它的 onclick 函数 jquery

javascript - 如何加载动态内容的html页面?

javascript - 如何在scss中使用if else条件

jquery - 视差仅适用于页面刷新,不适用于重定向

javascript - Cordova 地理定位不准确

javascript - 如何使用 JavaScript 获取网站中的所有 URL?

javascript - 单击按钮启动 fancyBox