简体   繁体   English

JavaScript无法在Safari中使用(在线)

[英]Javascript not working in safari (online)

It works fine offline and online on my IOS device, but not on desktop. 它可以在IOS设备上离线和在线正常运行,但不能在桌面上运行。 It pushes a small image file down once user scrolls over 100% window height: 用户滚动到超过100%的窗口高度时,它将下推一个小的图像文件:

    <script type="text/javascript">
    function update() {
        if ($(window).scrollTop() > $(window).height()) {
            $('.logo-small').animate({
                "top": '0px'
            }, 300);
        } else {
            $('.logo-small').animate({
                "top": '-90px'
            }, 300);
        }
    }

    setInterval(update, 1000);
</script>

Your condition should be like below to work in all devices. 您的情况应如下所示,才能在所有设备上正常工作。 Without calculating entire document height you will not sure whether the user reached bottom or not. 如果不计算整个文档的高度,您将无法确定用户是否到达底部。 If you need to show your image when user reach 100px from bottom, set value in variable bottomLimit. 如果您需要在用户从底部到达100px时显示图像,请在变量bottomLimit中设置值。

var bottomLimit = 0;
if ($(window).scrollTop() + $(window).height() > $(document).height() - bottomLimit)

Complete Code: 完整的代码:

<script type="text/javascript">
function update() {
var bottomLimit = 0;
    if ($(window).scrollTop() + $(window).height() > $(document).height() - bottomLimit) {
        $('.logo-small').animate({
            "top": '0px'
        }, 300);
    } else {
        $('.logo-small').animate({
            "top": '-90px'
        }, 300);
    }
}

setInterval(update, 1000);
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM