首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jssor:$Pause()不会暂停滑块

jssor:$Pause()不会暂停滑块
EN

Stack Overflow用户
提问于 2014-09-01 06:07:23
回答 2查看 1.7K关注 0票数 0

Jssor初始化:

代码语言:javascript
复制
        function imageAndVideoJssor()
        {
            jssor_slider_image_and_video = '';
            var slides = $('#jssor_all_play_show_slides>div');
            var slideCount = slides.length;
            var thumbNailNavigatorChanceToShow = slideCount < 2 ? 0 : 2;
            var _CaptionTransitions = [];
            _CaptionTransitions["MCLIP|B"] = {$Duration: 600, $Clip: 8, $Move: true, $Easing: $JssorEasing$.$EaseOutExpo};

            var displayPieces = 4;
            var arrowNavigatorSteps = 3;
            if (navigator.userAgent.match(/(iPhone|iPod|iPad|BlackBerry|IEMobile)/)) {
                displayPieces = 2;
                arrowNavigatorSteps = 1;
            }

            var options = {
                $AutoPlay: false,
                $FillMode: 2,
                $Loop: 0,
                $ThumbnailNavigatorOptions: {
                    $Class: $JssorThumbnailNavigator$,
                    $ChanceToShow: thumbNailNavigatorChanceToShow,
                    $DisplayPieces: displayPieces,
                    $ArrowNavigatorOptions: {
                        $Class: $JssorArrowNavigator$, //[Requried] Class to create arrow navigator instance
                        $ChanceToShow: 2, //[Required] 0 Never, 1 Mouse Over, 2 Always
                        $AutoCenter: 2, //[Optional] Auto center arrows in parent container, 0 No, 1 Horizontal, 2 Vertical, 3 Both, default value is 0
                        $Steps: arrowNavigatorSteps                                      //[Optional] Steps to go for each navigation request, default value is 1
                    }
                },
                $ArrowNavigatorOptions: {
                    $Class: $JssorArrowNavigator$,
                    $ChanceToShow: 0
                },
                $CaptionSliderOptions: {//[Optional] Options which specifies how to animate caption
                    $Class: $JssorCaptionSlider$, //[Required] Class to create instance to animate caption
                    $CaptionTransitions: _CaptionTransitions, //[Required] An array of caption transitions to play caption, see caption transition section at jssor slideshow transition builder
                    $PlayInMode: 0, //[Optional] 0 None (no play), 1 Chain (goes after main slide), 3 Chain Flatten (goes after main slide and flatten all caption animations), default value is 1
                    $PlayOutMode: 0                                 //[Optional] 0 None (no play), 1 Chain (goes before main slide), 3 Chain Flatten (goes before main slide and flatten all caption animations), default value is 1
                }
            };

            var jssorTagId = 'jssor_all_play_show';
            jssor_slider_image_and_video = new $JssorSlider$(jssorTagId, 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_slider_image_and_video.$Elmt.parentNode.clientWidth;
                if (parentWidth)
                    jssor_slider_image_and_video.$ScaleWidth(Math.min(parentWidth, 720));
                else
                    window.setTimeout(ScaleSlider, 30);
            }

            ScaleSlider();

            $(window).bind("load", ScaleSlider);
            $(window).bind("resize", ScaleSlider);
            $(window).bind("orientationchange", ScaleSlider);

            jssorResolutionAdjustor(jssorTagId);
            $(window).resize(function() {
                jssorResolutionAdjustor(jssorTagId);
            });
            //if (navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
            //    $(window).bind("orientationchange", ScaleSlider);
            //}
            //responsive code end
            setTimeout(function() {
                showAllImageVideoJssorJwPlayer();
            }
            , 0);

            jssor_slider_image_and_video.$On($JssorSlider$.$EVT_PARK, function(slideIndex, fromIndex) {
                console.log('from index = ' + fromIndex + 'slide index = ' + slideIndex);
                    showAllImageVideoJssorJwPlayer();
            });
        }

上面的代码用于初始化jssor,在该函数中,我最后调用了函数showAllImageVideoJssorJwPlayer(),其声明如下。我在初始化jssor之后调用了这个函数,在jssor的事件公园上调用了这个函数。

视频和图像控制代码:

代码语言:javascript
复制
    function showAllImageVideoJssorJwPlayer()
    {

        var slideCount = jssor_slider_image_and_video.$SlidesCount();
        console.log('slideCount = ' + slideCount);
        if (slideCount === 1)
        {
            var activeVideo = $('[id="jssor_all_play_show_slides"]:eq(1)>div:last-child img');
        } else {
            var activeVideo = $('.pav img:visible');
        }
        console.log('Video ' + activeVideo.data('video'));
        if (activeVideo.data('video') !== undefined)
        {
            console.log('inside video');
            jssor_slider_image_and_video.$Pause();
            var videoObj = {};
            videoObj.videoSrc = activeVideo.data('video');
            videoObj.thumbSrc = activeVideo.attr('src');

            jssorAllImageVideoPlayerInstance = jwplayer("jssor_all_video_screen").setup({
                file: videoObj.videoSrc,
                image: videoObj.thumbSrc,
                width: 720,
                height: 400
            });



            jssorAllImageVideoPlayerInstance.onReady(function() {

                jssorAllImageVideoPlayerInstance.play();

                jssorAllImageVideoPlayerInstance.onPlay(function() {
                    $('body').on('click', function() {
                        jssorAllImageVideoPlayerInstance.pause(true);
                        jssor_slider_image_and_video.$Pause();
                    });

                    jssor_slider_image_and_video.$Pause();
                });

                jssorAllImageVideoPlayerInstance.onComplete(function() {
                    jssor_slider_image_and_video.$Next();
                    jssorAllImageVideoPlayerInstance.remove();
                });
            });

        } else if (activeVideo.data('video') === undefined)
        {
            if (typeof jssorAllImageVideoPlayerInstance !== "undefined")
            {
                jssorAllImageVideoPlayerInstance.remove();
            }
            jssor_slider_image_and_video.$Play();
        }
    }

我喜欢暂停幻灯片放映,一旦视频被播放,我使用jssor_slider_image_and_video.$Pause();。代码到达console.log('inside video');,因此这清楚地表示在下一行幻灯片应该停止。但实际上它并没有阻止下滑来证明这一点,

在这里附上萤火虫屏幕截图

在控制台日志中,在视频中的第一次出现是红色边框,它本身就是红色的,jssor $pause应该工作,但是它不工作,不知道为什么。

EN

回答 2

Stack Overflow用户

发布于 2014-09-01 09:28:42

实例。$Pause调用阻止滑块自动播放。它不会突然冻结滑块。

实际上,如果滑块暂停,它将停留在当前幻灯片,直到您单击箭头或子弹按钮。

票数 0
EN

Stack Overflow用户

发布于 2014-09-01 13:46:30

不知道这是一个正确的解决方案,但我通过放置以下代码片段来解决这个问题

代码语言:javascript
复制
    if(typeof jssor_slider_image_and_video === 'object')
    {
        jssor_slider_image_and_video.$Pause();
        delete jssor_slider_image_and_video;
    }

就在函数imageAndVideoJssor()的实例化上面。

在以下代码之前

代码语言:javascript
复制
    var jssorTagId = 'jssor_all_play_show';
    jssor_slider_image_and_video = new $JssorSlider$(jssorTagId, options);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25599713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档