Stop JWPlayer when hidden the div with the player

浪子不回头ぞ 提交于 2019-12-06 10:58:12

问题


I have a site where I'm using a JavaScript to add or remove a css class. Using this method I hide a div or show a div, as I need it. It works great.

The problem is one div opens a Video with a JWplayer, when I hide the "window" or better say, the div. The sound is still playing, so I need a code to put stop on the video when someone clicks the "hide" button or close button.

How do you do that? I have no idea.

Thanks

HTML

 <div class="videoquon">
         <div class='my-video-close'></div>
<div id='my-video'></div>
<script type='text/javascript'>
    jwplayer('my-video').setup({
        file: 'qvideo.f4v',
        width: '600',
        height: '337'
    });
</script>
</div>

JavaScript

  $('div.vidreveal a').click(
                function(event) {
                    event.stopPropagation();
                    $('div.videoquon').slideToggle(300);
                }
            );

   $('div.my-video-close').click(
                function(event) {
                    event.stopPropagation();
                    $('div.videoquon').slideToggle(300);
                }
            );

回答1:


I don't know JW Player, but judging by their docs, I'm going to go with

$( 'div.my-video-close' ).click( function( event ) {
    event.stopPropagation();
    jwplayer( 'my-video' ).stop();
    $( 'div.videoquon' ).slideToggle( 300 );
});

...or jwplayer( 'my-video' ).pause(); depending on the desired effect.



来源:https://stackoverflow.com/questions/15909006/stop-jwplayer-when-hidden-the-div-with-the-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!