简体   繁体   English

jQuery window.onscroll侦听器在Safari中未显示和显示:内联

[英]jquery window.onscroll listener to display:none and display:inline not appearing in Safari

I am testing in Safari 11.0.3 我正在Safari 11.0.3中进行测试

Site: https://3milychu.github.io/met-erials 网站: https//3milychu.github.io/met-erials

I have the following function to create a header that pops out the selected item upon scroll 我具有以下函数来创建标题,该标题在滚动时弹出所选项目

function scrollState () {


var elmnt = document.getElementById("title");
var rep = elmnt.offsetTop;

if (window.pageYOffset >= elmnt.offsetHeight) { 
       // $('input:not(:checked').parent().hide();
       $('input:not(:checked').parent().css("display","none");
       $("input:checked").css("display", "inline");
        $("label").css("marginLeft", "35%");
       $("label" ).css("fontSize", "4em");
       $("label" ).css("textAlign", "center");
       $("input:checked").css("float", "none");
        $("input:checked").css("verticalAlign", "top");
       $("input[type=radio]").css("width", "3em");
       $("input[type=radio]").css("height", "3em");
        $("input:checked").css("fontSize", "0.5em");
} else  {
        $("input:checked").css("display", "inline")
        $("label").css("marginLeft", "0%");
        $("label" ).css("textAlign", "none");
       $("input:checked").css("float", "right");
       $("input[type=radio]").css("width", "2em");
       $("input[type=radio]").css("height", "2em");
        $("input:checked").css("fontSize", "11px");
        // $('input:not(:checked').parent().show();
        $('input:not(:checked').parent().css("display","inline-block");
        $("label").css("fontSize", "1.5em");

    };
};

I call it by: 我称其为:

window.onscroll = function() {scrollState()};

Why is this not working in Safari? 为什么这在Safari中不起作用? I commented out the .hide() method after seeing that Safari needs it to be replaced with .css("display","none"). 在看到Safari需要将其替换为.css(“ display”,“ none”)之后,我注释了.hide()方法。

This works in Chrome and Firefox as desired (when you use the .hide() and .show() methods) 这可以根据需要在Chrome和Firefox中使用(当您使用.hide()和.show()方法时)

您的$('input:not(:checked').parent().css("display","none"); (替换.show()那个)需要为('display', 'inline-block') ?您希望元素显示,但是您正在编写('display', 'none')

There was a syntax error. 发生语法错误。

$('input:not(:checked').parent().css("display","inline-block");

should be 应该

$('input:not(:checked)').parent().css("display","inline-block");

This resolved the issue. 这解决了问题。

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

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