【问题标题】:iOS Safari pauses animation on window.location.href = ...?iOS Safari 在 window.location.href = ... 上暂停动画?
【发布时间】:2019-10-02 04:18:03
【问题描述】:

我有来自https://codepen.io/anon/pen/ZNLyGe 的以下代码,当用户单击图标导航到同一网站的另一部分时,它会显示等待栏动画。

onclick Javascript 使用:

window.location.href = strNewURL;

它在桌面浏览器上运行良好,但在 iOS 上,Safari 会在动画到达 window.location.href 行时立即冻结。

有没有办法阻止 iOS Safari 停止该动画?

HTML

<div class="dvProgressBarInfinite" id="dvIDProgressBarInfinite">
    <div class="indeterminate"></div>
</div>

CSS

/* Progress Bar */
.dvProgressBarInfinite {
    position: absolute;
    height: 2px;
    display: block;
    width: 100%;
    background-color: #cfcfcf;
    border-radius: 2px;
    background-clip: padding-box;
    margin: 0.5rem 0 1rem 0;
    overflow: hidden;
}

.dvProgressBarInfinite .indeterminate {
    background-color: #000000;
}

.dvProgressBarInfinite .indeterminate:before {
    content: '';
    position: absolute;
    background-color: inherit;
    top: 0;
    left: 0;
    bottom: 0;
    will-change: left, right;
    -webkit-animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
    animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}

.dvProgressBarInfinite .indeterminate:after {
    content: '';
    position: absolute;
    background-color: inherit;
    top: 0;
    left: 0;
    bottom: 0;
    will-change: left, right;
    -webkit-animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
    animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
    -webkit-animation-delay: 1.15s;
    animation-delay: 1.15s;
}

@-webkit-keyframes indeterminate {
    0% {
        left: -35%;
        right: 100%;
    }

    60% {
        left: 100%;
        right: -90%;
    }

    100% {
        left: 100%;
        right: -90%;
    }
}

@keyframes indeterminate {
    0% {
        left: -35%;
        right: 100%;
    }

    60% {
        left: 100%;
        right: -90%;
    }

    100% {
        left: 100%;
        right: -90%;
    }
}

@-webkit-keyframes indeterminate-short {
    0% {
        left: -200%;
        right: 100%;
    }

    60% {
        left: 107%;
        right: -8%;
    }

    100% {
        left: 107%;
        right: -8%;
    }
}

@keyframes indeterminate-short {
    0% {
        left: -200%;
        right: 100%;
    }

    60% {
        left: 107%;
        right: -8%;
    }

    100% {
        left: 107%;
        right: -8%;
    }
}

JAVASCRIPT

function fJToolbar2Click(intColumnNumber)
{
    var strURL = "<%=strClsToolbar2URLPrefix%>";
    var strURLSuffix = "";

    switch(intColumnNumber) {
        case 1:
            strURLSuffix ='<%=strClsToolbar2ClickURLsTarget(1)%>';
            break;
        case 2:
            strURLSuffix ='<%=strClsToolbar2ClickURLsTarget(2)%>';
            break;
        case 3:
            strURLSuffix ='<%=strClsToolbar2ClickURLsTarget(3)%>';
            break;
        case 4:
            strURLSuffix ='<%=strClsToolbar2ClickURLsTarget(4)%>';
            break;
        };

    fJProgressIndeterminateShow();

    setTimeout(function (){
    window.location.href = strURL + strURLSuffix;  
    }, 200);        

}    

function fJProgressIndeterminateShow()
{       
   var dv1 = document.getElementById("dvIDProgressBarIndeterminate");
   dv1.style.display="inline-block";        
}

【问题讨论】:

    标签: javascript ios css css-animations mobile-safari


    【解决方案1】:

    我最终使用了这个,它在“保存到主屏幕”iOS webapp/site 中非常适合我。

    setTimeout(function(){
        window.location.href = strNewURL;
    }, 200);
    

    我当时可能偶然发现了这个问题Why isnt window.location.href= not forwarding to page using Safari?

    在这里看到它对我有用https://dev.joshmoto.wtf/unearth.ed/wp/ ...我对没有预加载 fontawesome 微调器感到内疚,所以有时微调器在跳到下一页之前没有及时渲染。但是您的动画是纯 css,所以应该不是问题。

    【讨论】:

    • 您是否尝试过增加超时作为测试?喜欢再试一试.. 1000
    • 是的,我什至尝试了 5000。请参阅上面添加的 Javascript 部分。
    • 参见上面添加的 Javascript 部分。我刚刚在 iPad Pro 11 英寸 Safari 和 iPhone 10S Max Safari 上进行了测试。
    • 我刚刚在 iPhone 6s 上试过这个并且工作正常app.joshmoto.wtf/test.php 但是当使用超时 1000 时,进度条只能使其 50% 跨度。您是否试图从左侧获得完美的完整动画跳到下一页之前?
    • 是的。我们希望它转来转去,直到返回下一页。有时,如果手机用户使用 3G 或 4G,或者他们的 wifi 速度很慢,或者服务器很忙等,这可能需要长达 5 秒。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 2013-11-25
    • 2012-08-21
    相关资源
    最近更新 更多