【问题标题】:Jssor - Creating Margins with Full Width SliderJssor - 使用全宽滑块创建边距
【发布时间】:2015-04-17 21:10:26
【问题描述】:

我正在使用“全宽滑块”,但我不希望它是全宽的,我希望它在占据页面约 80% 的 div 内是全宽的。我在调整slider1_container 的宽度时遇到了麻烦(例如,如果我死了它会增加大小的数字)。所以我决定创建自己的 div 并将其放在其中。问题是,当我为自己的 div 设置 css 样式时,margin-left: 10px;或左边距:10%;它将幻灯片推到一边(10px 或 10%),这将生成一个滚动条,无论我的页面有多大。我希望容器(可以是我的容器)占据页面的 80%,每边留出 10% 的边距。 Margin-right 似乎也对我的幻灯片容器没有任何作用。

用我的代码更新:

 //responsive code begin
 //you can remove responsive code if you don't want the slider scales while window resizes
 function ScaleSlider() {
var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
if (parentWidth) {
    var sliderWidth = parentWidth;

    //keep the slider width no more than 800
    sliderWidth = Math.min(sliderWidth, 1200);

    jssor_slider1.$ScaleWidth(sliderWidth);
}
else
    window.setTimeout(ScaleSlider, 30);
 }
 ScaleSlider();

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


 <div class="left-slide-container">

<div id="slider1_container" style="position: relative; margin: 0 auto;
    top: 0px; left: 0px; width: 1200px; height: 500px; overflow: hidden;">



<!-- Slides Container -->
    <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 1200px;
        height: 500px; overflow: hidden;">
</div>

CSS:

.left-slide-container {
margin-left: 10%;
margin-right: 10%;
width:80%;
}

【问题讨论】:

    标签: jquery html css jssor


    【解决方案1】:

    你做得对。请使用以下代码在您的容器中安装 jssor 滑块。

    //responsive code begin
    //you can remove responsive code if you don't want the slider scales while window resizes
    function ScaleSlider() {
        var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
        if (parentWidth) {
            var sliderWidth = parentWidth;
    
            //keep the slider width no more than 800
            sliderWidth = Math.min(sliderWidth, 800);
    
            jssor_slider1.$ScaleWidth(sliderWidth);
        }
        else
            window.setTimeout(ScaleSlider, 30);
    }
    ScaleSlider();
    
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
    //responsive code end
    

    【讨论】:

    • 谢谢。它现在不会扩展(即响应式)。也许我的“slider1_container”和“幻灯片”的宽度也需要是一个百分比?不过好像不太喜欢..
    猜你喜欢
    • 2014-02-27
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    相关资源
    最近更新 更多