当我添加时 jssor 滑块(边距:0 自动;)它居中但停止工作

jssor slider when i addin (margin: 0 auto;) it centers but stops working

我已经为滑块配置了我想要的字幕,所有这些都在屏幕左侧完美运行,但我希望它居中。

我一直在寻找答案,并在许多线程中发现将 'margin: 0 auto;' 添加到幻灯片容器就可以解决问题。但是在我的例子中,当我将 'margin: 0 auto;' 添加到滑块容器时,它确实将容器移动到中心但是它停止工作,有点卡住我并且幻灯片如果出现是块状的。

删除边距设置可修复滑块并将其放回左对齐状态,因此其他一切似乎都能正常工作,但我无法将其放在中间并正常工作。

    <script>       
          jQuery(document).ready(function ($) {
            var _CaptionTransitions = [];      
          _CaptionTransitions["L"] = {$Duration:900,$Zoom:1,$Easing:$JssorEasing$.$EaseInCubic};

          var options = {
                    $AutoPlay: true,                                    
                    $DragOrientation: 3,                                
                    $CaptionSliderOptions: {                            
                        $Class: $JssorCaptionSlider$,                   
                        $CaptionTransitions: _CaptionTransitions,       
                        $PlayInMode: 1,                                 
                        $PlayOutMode: 3                                 
                    }
                };

        var jssor_slider1 = new $JssorSlider$("slider1_container", options);
        //responsive code begin
    function ScaleSlider() {
        var windowWidth = $(window).width();

        if (windowWidth) {
            var windowHeight = $(window).height();
            var originalWidth = jssor_slider1.$OriginalWidth();
            var originalHeight = jssor_slider1.$OriginalHeight();

            if (originalWidth / windowWidth > originalHeight / windowHeight) {
                jssor_slider1.$ScaleHeight(windowHeight);
            }
            else {
                jssor_slider1.$ScaleWidth(scaleWidth);
            }
        }
        else
            window.setTimeout(ScaleSlider, 30);
    }

    ScaleSlider();

    if (!navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|IEMobile)/)) {
        $(window).bind('resize', ScaleSlider);
    }
    else {
        $(window).bind("orientationchange", ScaleSlider);
    }
    //responsive code end
            });  
        </script>




> <!-- Jssor Slider Begin -->
>       <!-- You can move inline styles to css file or css block. -->
>       <div id="slider1_container" style="position: relative; margin: 0 auto; width: 600px; height: 480px;">
>         <!-- Slides Container -->
>         <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width:600px; height:480px; overflow: hidden;">
>           <div> <img u="image" src="portfolio/synthetic and teak deck.jpg" />
>           <div u="caption" t="L" style="position: absolute;
>     top: 125px; left: 125px; width: 350px;height: 50px;"><Code>Synthetic and teak decking</code>
>     </div>
>           </div>
>           <div> <img u="image" src="portfolio/teak pool deck.jpg" />
>           <div u="caption" t="L" style="position: absolute;
>     top: 125px; left: 125px; width: 350px;height: 50px;"><code>Teak decking around the pool</code>
>     </div>
>           </div>

非常感谢您的帮助并为我指明正确的方向

代码有误,

请替换

jssor_slider1.$ScaleWidth(scaleWidth);

jssor_slider1.$ScaleWidth(windowWidth);

请注意,仅当父元素比元素宽时,'margin: 0 auto;' 才会将元素中心与其父元素对齐。因此,它在全屏滑块的情况下不起作用。这是一个技巧,请按如下方式将滑块放入包装器中,

<div style="position: relative; width: 100%; background-color: #003399; overflow: hidden;">
    <div style="position: relative; left: 50%; width: 5000px; text-align: center; margin-left: -2500px;">
    </div>
</div>

最后,您的代码应该如下所示,

<script>
    jQuery(document).ready(function ($) {
        var _CaptionTransitions = [];
        _CaptionTransitions["L"] = { $Duration: 900, $Zoom: 1, $Easing: $JssorEasing$.$EaseInCubic };

        var options = {
            $AutoPlay: true,
            $DragOrientation: 3,
            $CaptionSliderOptions: {
                $Class: $JssorCaptionSlider$,
                $CaptionTransitions: _CaptionTransitions,
                $PlayInMode: 1,
                $PlayOutMode: 3
            }
        };

        var jssor_slider1 = new $JssorSlider$("slider1_container", options);
        //responsive code begin
        //you can remove responsive code if you don't want the slider to scale along with window
        function ScaleSlider() {
            var windowWidth = $(window).width();

            if (windowWidth) {
                var windowHeight = $(window).height();
                var originalWidth = jssor_slider1.$OriginalWidth();
                var originalHeight = jssor_slider1.$OriginalHeight();

                if (originalWidth / windowWidth > originalHeight / windowHeight) {
                    jssor_slider1.$ScaleHeight(windowHeight);
                }
                else {
                    jssor_slider1.$ScaleWidth(windowWidth);
                }
            }
            else
                window.setTimeout(ScaleSlider, 30);
        }

        ScaleSlider();

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

<div style="position: relative; width: 100%; background-color: #003399; overflow: hidden;">
    <div style="position: relative; left: 50%; width: 5000px; text-align: center; margin-left: -2500px;">
        <!-- Jssor Slider Begin -->
        <div id="slider1_container" style="position: relative; margin: 0 auto; width: 600px; height: 300px;">
            <!-- Slides Container -->
            <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width:600px; height:300px; overflow: hidden;">
                <div>
                    <img u="image" src="portfolio/synthetic and teak deck.jpg" />
                    <div u="caption" t="L" style="position: absolute;
 top: 125px; left: 125px; width: 350px;height: 50px;">
                        <code>Synthetic and teak decking</code>
                    </div>
                </div>
                <div>
                    <img u="image" src="portfolio/teak pool deck.jpg" />
                    <div u="caption" t="L" style="position: absolute;
 top: 125px; left: 125px; width: 350px;height: 50px;">
                        <code>Teak decking around the pool</code>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>