JSSOR:滑块在加载时无法正确缩放

时间:2015-09-25 04:27:35

标签: javascript jssor

我试图弄清楚如何在页面加载时缩放JSSOR容器高度。

当滑块在高宽度页面上加载时,滑块宽度和高度在调整大小时会平滑地缩放。但是当页面在移动设备上加载时,容器高度将不会像滑块在高宽度页面上加载时那样缩放。

问题在于: http://screencast.com/t/W6fldyjtuCAp

从高宽度页面加载调整大小时,它可以正常工作: http://screencast.com/t/1lErSBxu

但是当我在JSSOR网站上看到该演示时,该缩放在移动页面加载时运行顺畅。这是我的JSSOR代码:

jssor_slider1_starter = function (containerId) {

        var options = {

            $AutoPlay: true,                                    //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false

            $AutoPlaySteps: 1,                                  //[Optional] Steps to go for each navigation request (this options applys only when slideshow disabled), the default value is 1

            $AutoPlayInterval: 4000,                            //[Optional] Interval (in milliseconds) to go for next slide since the previous stopped if the slider is auto playing, default value is 3000

            $PauseOnHover: 1,                               //[Optional] Whether to pause when mouse over if a slider is auto playing, 0 no pause, 1 pause for desktop, 2 pause for touch device, 3 pause for desktop and touch device, 4 freeze for desktop, 8 freeze for touch device, 12 freeze for desktop and touch device, default value is 1

            $Loop: 0,                                       //[Optional] Enable loop(circular) of carousel or not, 0: stop, 1: loop, 2 rewind, default value is 1

            $ArrowKeyNavigation: true,                          //[Optional] Allows keyboard (arrow key) navigation or not, default value is false

            $SlideDuration: 500,                                //[Optional] Specifies default duration (swipe) for slide in milliseconds, default value is 500

            $MinDragOffsetToSlide: 20,                          //[Optional] Minimum drag offset to trigger slide , default value is 20

            $SlideSpacing:0,                                    //[Optional] Space between each slide in pixels, default value is 0

            $Cols: 1,                                  //[Optional] Number of pieces to display (the slideshow would be disabled if the value is set to greater than 1), the default value is 1

            $Align: 0,                                //[Optional] The offset position to park slide (this options applys only when slideshow disabled), default value is 0.

            $UISearchMode: 1,                                   //[Optional] The way (0 parellel, 1 recursive, default value is 1) to search UI components (slides container, loading screen, navigator container, arrow navigator container, thumbnail navigator container etc).

            $PlayOrientation: 1,                                //[Optional] Orientation to play slide (for auto play, navigation), 1 horizental, 2 vertical, 5 horizental reverse, 6 vertical reverse, default value is 1

            $DragOrientation: 3,                                //[Optional] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $Cols is greater than 1, or parking position is not 0)

            $FillMode: 1,



            $ThumbnailNavigatorOptions: {

                $Class: $JssorThumbnailNavigator$,              //[Required] Class to create thumbnail navigator instance

                $ChanceToShow: 2,                               //[Required] 0 Never, 1 Mouse Over, 2 Always

                $Loop: 2,                                       //[Optional] Enable loop(circular) of carousel or not, 0: stop, 1: loop, 2 rewind, default value is 1

                $Rows: 1,                                      //[Optional] Specify lanes to arrange thumbnails, default value is 1

                $SpacingX: 4,                                   //[Optional] Horizontal space between each thumbnail in pixel, default value is 0

                $SpacingY:0,                                   //[Optional] Vertical space between each thumbnail in pixel, default value is 0

                $Cols: 4,                              //[Optional] Number of pieces to display, default value is 1

                $Align: 0,                            //[Optional] The offset position to park thumbnail

                $Orientation: 2,                                //[Optional] Orientation to arrange thumbnails, 1 horizental, 2 vertical, default value is 1

                $NoDrag: false                             //[Optional] Disable drag or not, default value is false

            }



        };



        var jssor_slider1 = new $JssorSlider$(containerId, options);

        //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 810
                sliderWidth = Math.min(sliderWidth, 1000);

                jssor_slider1.$ScaleWidth(sliderWidth);
            }
            else
                $Jssor$.$Delay(ScaleSlider, 30);
        }

        ScaleSlider();
        // $Jssor$.$AddEvent(window, "load", ScaleSlider);
        $Jssor$.$AddEvent(window, "load", $Jssor$.$WindowResizeFilter(window, ScaleSlider));

        $Jssor$.$AddEvent(window, "resize", $Jssor$.$WindowResizeFilter(window, ScaleSlider));
        $Jssor$.$AddEvent(window, "orientationchange", ScaleSlider);
        //responsive code end
}

jssor_slider1_starter('slider1_container');

我在这里缺少什么?我试图将代码与JSSOR演示选项匹配,但它也不起作用。

谢谢你提前!

1 个答案:

答案 0 :(得分:1)

我设法解决了这个问题。最初我使用%width作为滑块容器,幻灯片图像和缩略图皮肤CSS。然后我把它改成px宽度,它现在完美地工作了。