在976px宽度后添加/删除CSS样式?

时间:2017-10-22 11:47:14

标签: javascript jquery html css fullpage.js

/*Fade in effect & one pager*/
.fullpage-wrapper {
    width: 100%!important;
    transform: none!important;
}

.fp-section {
    width: 100%!important;
    position: absolute;
    left: 0;
    top: 0;
    visibility: hidden;
    opacity: 0;
    z-index: 0;
    transition: all .7s ease-in-out;
}

.fp-section.active {
    visibility: visible;
    opacity: 1;
    z-index: 1;
}
/* Remove transition when website is still loading */
body {display:none}
body[class*="fp-viewing-"] {display:block}

我想为移动用户删除968px宽度以下的这些给定样式。我怎样才能在javascript或jquery中实现这一点?也可以将其他权利打开吗?

if ($(window).width() < 967) {
   *remove these styles but how?*
}
else {
   *keep them/or do nothing*
}

4 个答案:

答案 0 :(得分:5)

你可以只使用css:

@media only screen and (min-width : 967px) {
    /*Your styles */
}

答案 1 :(得分:2)

@media only screen and (max-width: 967px) {
    .fullpage-wrapper {
        width: 100%!important;
        transform: none!important;
    }

.    fp-section {
        width: 100%!important;
        position: absolute;
        left: 0;
        top: 0;
        visibility: hidden;
        opacity: 0;
        z-index: 0;
        transition: all .7s ease-in-out;
    }

    .fp-section.active {
        visibility: visible;
        opacity: 1;
        z-index: 1;
    }
    /* Remove transition when website is still loading */
    body {display:none}
    body[class*="fp-viewing-"] {display:block}
}

答案 2 :(得分:0)

您可以使用jQuery https://jsfiddle.net/my5Luevc/

来解决问题

$(window).resize(function(){
  if ($(window).width() < 967) {
    $('div').addClass('width976');
  }
  else {
     $('div').removeClass('width976');
  }
});
div {
  height: 100px;
  width: 100px;
  border: 1px solid #ccc;
}

.width976{
  background: rgba(255,0,0,0.4);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>

在调整屏幕大小时,您可以看到该课程正在动态添加&amp;除去。

希望这会对你有所帮助。

答案 3 :(得分:0)

如果您正在使用fullPage.jsfadingEffect extension,正如您的代码和标记似乎指出的那样,那么您可以使用fullPage.js回调和函数来解决这个问题。方式:

$('#fullpage').fullPage({
    responsiveWidth: 976,
    afterResponsive: function(isResponsive){
        if(isResponsive){
            $.fn.fullpage.fadingEffect.turnOff();
        }
        else{
            $.fn.fullpage.fadingEffect.turnOn();
        }
    }
});