Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 根据我的媒体查询禁用JS_Ios_Css_Media Queries_Javascript - Fatal编程技术网

Ios 根据我的媒体查询禁用JS

Ios 根据我的媒体查询禁用JS,ios,css,media-queries,javascript,Ios,Css,Media Queries,Javascript,我在我的网站(wordpress)上使用了一个JS脚本,以便在滚动时获得一个顶部标题。 我现在正在处理手机和ipad的媒体查询,因为有一些问题 我想在手机和ipad上淡化这个JS,这样我的标题就相对而言了。 我找不到办法, 有人能帮忙吗 以下是我的JS代码: $(function () { // Check the initial Poistion of the Sticky Header var stickyHeaderTop = $('#stickyheader').offs

我在我的网站(wordpress)上使用了一个JS脚本,以便在滚动时获得一个顶部标题。 我现在正在处理手机和ipad的媒体查询,因为有一些问题

我想在手机和ipad上淡化这个JS,这样我的标题就相对而言了。 我找不到办法, 有人能帮忙吗

以下是我的JS代码:

$(function () {
    // Check the initial Poistion of the Sticky Header
    var stickyHeaderTop = $('#stickyheader').offset().top;

    $(window).scroll(function () {
        if ($(window).scrollTop() === stickyHeaderTop+1) {
            $('#stickyheader').hide();
            console.log('p');
        }
        if ($(window).scrollTop() > stickyHeaderTop) {
            $('#stickyheader').fadeIn(500).css('position','fixed');
            $('#stickyalias').css('display', 'block');
            var mT = $('#stickyheader').css('height');
            $('#stickyheader').next('.post').css('marginTop', mT);
        }else{
            $('#stickyheader').css({
                position: 'relative',
            });
            $('#stickyheader').next('.post').css('marginTop', '0');
        }
    });
});
还有我的css:

#header {background-color: #f8f8f8;top: 0;padding-top: 20px;}
#stickyheader { width: 100%;padding-top:10px;top: 0;z-index: 1000;padding-bottom: 10px;line-height: 24px;position:relative;background-color: #f8f8f8;}
#unstickyheader {height:auto;}
我的媒体查询css:

/* Media queries!
-------------------------------------------------------------------------------*/

/*IPAD*/

@media screen and (max-device-width : 1024px) {

}

/*IPHONE*/
@media screen  and (max-device-width : 568px) and (min-device-width : 320px)   {
#menu-menu {list-style:none;font-size: 35px;font-weight: 700}
}
最后是一把JS小提琴:


非常感谢您的帮助,

这可能是您的答案:

JavaScript的CSS媒体查询

与您的代码相关的示例:

if (matchMedia("media query here").matches) {
    window.onscroll = ...
}

谢谢@Greg Burghardt,我认为有一种更简单的方法可以做到这一点。。。我还在搜索汉克斯@Greg Burghardt。。。我正在尝试完成你给我的JS代码。。。如果(matchMedia(“@media screen and(最大设备宽度:568px)和(最小设备宽度:320px)”).matches){}正确吗?它似乎不起作用