css - 基于窗口宽度的 Jssor slider 可变宽度

标签 css slider width jssor

是否可以根据窗口大小(媒体查询)将幻灯片更改为固定宽度?我不希望它缩放或处于 percetange,只是根据窗口大小固定宽度。

例如这样的东西

@media screen and (min-width: 320px) {
   .slides {
      width: 200px;
   }
}
@media screen and (min-width: 980px) {
   .slides {
      width: 600px;
   }
}

因为正确知道,它始终具有基于窗口宽度的内联样式,并且无法对其进行任何操作。我尝试在 css 中使用 !important,但它只能以这种方式工作

大 -> 小(幻灯片较小) -> 大(幻灯片较大)

但不是这样

小 -> 大(幻灯片仍然很小)-> 没关系

感谢回复

编辑:

这是我的代码

HTML:

<div id="slider1_container" class="slider1_container">
    <div u="slides" id="selectedImg">
       {% for item in info.photos %}
          <div class="sliderImgs">
             <img u="image" src="{{ item|url_for_static }}" class="sliderImgs"/>                                                                        
              <img u="thumb" src="{{ item|url_for_static }}"/>
           </div>
        {% endfor %}
    </div>
<div u="thumbnavigator" class="jssort07">
<!-- Thumbnail Item Skin Begin -->
<div u="slides" id="thumbnailSlides">
     <div u="prototype" class="p">
          <div u="thumbnailtemplate" class="i"></div>
          <div class="o"></div>
     </div>
</div>
</div>
     <span u="arrowleft" class="leftArrow"></span>
     <span u="arrowright" class="rightArrow"></span>
 </div>

CSS:

@media screen and (min-width: 320px){
.leftArrow, .rightArrow {
    position: absolute;
    top: 205px;
    height: 52px;
    width: 15px;
    cursor: pointer;
}
.leftArrow {
    left: 10px;
    background: url('/static/images/sprite320.png') -92px -3px;
}
.rightArrow {
    right: -10px;
    background: url('/static/images/sprite320.png') -114px -2px;
}
.jssort07 {
    position: relative;
    top: 476px;
}
.slider1_container {
    position: relative;
    width: 298px !important;
    height: 460px !important;
    margin-top: 20px;
    margin-bottom: 15px;
}
#thumbnailSlides {
    display: none;
    background-color: black;
}
#selectedImg {
    position: absolute;
    top: 0;
    left: 77.5%;
    width: 298px !important;
    height: 446px !important;
    margin-left: -220px;
    overflow: hidden;
}
.sliderImgs {
    max-width: 298px !important;
    max-height: 446px !important;
}
}
@media screen and (min-width: 768px){
.leftArrow, .rightArrow {
        position: absolute;
        top: 215px;
        height: 104px;
        width: 31px;
        cursor: pointer;
    }
    .leftArrow {
        left: 50px;
        background: url('/static/images/imagesprite.png') -219px -8px;
    }
    .rightArrow {
        right: 115px;
        background: url('/static/images/imagesprite.png') -268px -8px;
    }
    .jssort07 {
        position: relative;
        top: 676px;
        max-width: 600px;
        height: 116px;
    }
    .jssort07 .p {
        width: 80px;
        height: 116px;
    }
    .jssort07 .pav {
        opacity: 0.8;
    }
    .jssort07 .i {
        width: 80px;
        height: 116px;
    }
    .slider1_container {
        width: 593px !important;
        height: 794px !important;
        margin-bottom: 15px;
    }
    #thumbnailSlides {
        display: block;
        left: 25px;
        height: 116px;
        background-color: black;
    }
    #selectedImg {
        position: absolute;
        top: 0;
        left: 44.5%;
        width: 439px !important;
        height: 657px !important;
        margin-left: -220px;
        overflow: hidden;
    }
    .sliderImgs {
        max-width: 439px !important;
        max-height: 657px !important;
    }
}

最佳答案

将内联样式移动到 css block 并为各种媒体屏幕指定不同的大小是正确的。

请注意, 按照您提到的方式,jssor slider 将保持初始大小,不会根据窗口大小调整。

顺便说一句,下面的代表什么?

big -> small (slides are smaller) -> big (slides are bigger)

but not this way

small -> big (slides are still small) -> doesn't matter

编辑

请启用响应式代码并在 ScaleSlider 函数中指定逻辑来缩放 slider 而不是 css 规则。

//responsive code begin
//you can remove responsive code if you don't want the slider scales while window resizes
function ScaleSlider() {
    var bodyWidth = document.body.clientWidth;
    if (bodyWidth) {
        var sliderWidth = bodyWidth;
        if (bodyWidth >= 980) {
            sliderWidth = 600;
        }
        else if (bodyWidth >= 320) {
            sliderWidth = 200;
        }
        jssor_slider1.$ScaleWidth(bodyWidth);
    }
    else
        window.setTimeout(ScaleSlider, 30);
}
ScaleSlider();

$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end

关于css - 基于窗口宽度的 Jssor slider 可变宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30017949/

相关文章:

php - 用于在 PHP 中解析 HTML 的 CSS 选择器

javascript - 光滑 slider - 当到达最后一张幻灯片时快退到第一张幻灯片

JavaFX Slider : Track length? 刻度标签颜色?

html - CSS 有奇怪的问题

html - 显示隐藏 <li> 时,无序列表不是 'moving down'

css - IE 中背景位置的问题

excel - 在Excel VBA中动态调整组合框的宽度

css - iframe 宽度属性被忽略

css - 如何将背景图像放在 <div> block 中并表现为 "responsive"

javascript - 在版本 6.1.8 中,单击按钮时 Revolution slider 如何再次启动(播放)?