javascript - 垂直时间轴在 chrome 浏览器中不起作用

标签 javascript css ruby-on-rails google-chrome

我对 ruby​​ on rails 应用程序使用垂直时间轴。除了 chrome 浏览器,这很好用。动画不适用于谷歌浏览器。我认为这是来自脚本!!!!任何人都可以建议解决方案。我的脚本是,

<script>
jQuery(document).ready(function($){
    var timelineBlocks = $('.cd-timeline-block'),
        offset = 0.8;

    //hide timeline blocks which are outside the viewport
    hideBlocks(timelineBlocks, offset);

    document.getElementById("body").onscroll = function() {myFunction()};

    //on scolling, show/animate timeline blocks when enter the viewport
    function myFunction() {
        (!window.requestAnimationFrame) 
            ? setTimeout(function(){ showBlocks(timelineBlocks, offset); }, 100)
            : window.requestAnimationFrame(function(){ showBlocks(timelineBlocks, offset); });
    }

    function hideBlocks(blocks, offset) {
        blocks.each(function(){
            ( $(this).offset().top > $(window).scrollTop()+$(window).height()*offset ) && $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
        });
    }

    function showBlocks(blocks, offset) {
        blocks.each(function(){
            ( $(this).offset().top <= $(window).scrollTop()+$(window).height()*offset && $(this).find('.cd-timeline-img').hasClass('is-hidden') ) && $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
        });
    }
});


谢谢。

最佳答案

它的 document.getElementById("body").onscroll = function() {myFunction()}; 在 chrome 上不能正常工作。

将此脚本用于 onScroll 事件:

$(window).on('scroll', function(){
    (!window.requestAnimationFrame) 
        ? setTimeout(function(){ showBlocks(timelineBlocks, offset); }, 100)
        : window.requestAnimationFrame(function(){ showBlocks(timelineBlocks, offset); });
});

引用:https://codyhouse.co/gem/vertical-timeline/

让我知道您的反馈! 谢谢

关于javascript - 垂直时间轴在 chrome 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606865/

相关文章:

javascript - 将 HTML Collection 中的值存储在数组中?

javascript - 当我将缩略图附加到 DIV 时,如何以特定模式定位缩略图?

javascript - 请帮我把这个脚本转换成一个简单的图像 slider

html - 如何在 HTML 电子邮件 css 中对齐表格

ruby-on-rails - 在没有 Lighttpd/Apache 的情况下服务 Web 应用程序

ruby-on-rails - 删除记录之前不会出现确认弹出窗口

javascript - 动态 HTML 页面内容

html - 相对表格单元格中的垂直对齐

html - 无法使用 youtube 和响应式调整容器大小

ruby-on-rails - 我是否需要手动为 HABTM 连接表创建迁移?