简体   繁体   English

如何在媒体查询CSS中禁用jQuery属性

[英]How to disable jQuery properties in media query css

How to remove or disable jQuery properties (Class and Id) in media query css? 如何在媒体查询CSS中删除或禁用jQuery属性(类和ID)? I want to remove or disable the properties if it reaches to 991px size. 如果大小达到991px,我想删除或禁用属性。

Here's my code. 这是我的代码。

$(window).scroll(function() {
        if ($(this).scrollTop() > 1){  
            $('#stickyHeader').addClass("sticky01");
            $('.site-title').attr("id", "stSize");        
            $('#site-navigation').addClass("stNavSize");        
        }else{
            $('#stickyHeader').removeClass("sticky01");
            $('.site-title').removeAttr("id", "stSize");
            $('#site-navigation').removeClass("stNavSize");
            $('.site-title').addClass("stSize2");
            $('#site-navigation').addClass("stNavSize2");
        }
    });

Thanks for the help :) 谢谢您的帮助 :)

You could make a new class or id with 991px and set it's display=none, 您可以使用991px创建一个新的类或ID,并将其设置为display = none,

@media you can addClass for screen larger than 991px @media,您可以为大于991px的屏幕添加class

I hope it helps, otherwise write me in comment and I will be glad to help you 希望对您有所帮助,否则请写评论给我,我们将很高兴为您提供帮助

CSS media queries to change elements at some viewport breakpoint CSS媒体查询以在某些视口断点处更改元素

/* CSS for > 991px */

.element {
  color: red;
}

/* CSS for < 991px */

@media (max-width: 991px) {
  .element {
    color: blue;
  }
}

jQuery to add/remove classes, id's etc, on load and resize jQuery在loadresize添加/删除类,ID等

$(window).on('load resize',function() {
 if ($(this).width() > 991) {
     $('#stickyHeader').addClass("sticky01");
 } else {
      $('#stickyHeader').removeClass("sticky01");
 }
});

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

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