【发布时间】:2015-02-09 09:45:38
【问题描述】:
有没有人想到在滑块中处理 Iframe 视频/音频,并有可能滑动它并仍然通过单击它来播放它?
我试图在 iframe 上放置一个叠加层并将事件发送到 iframe,但它似乎不起作用:-/
这是我之前的尝试: http://codepen.io/Anddo0/pen/PwOWxZ
JS部分:
var iFrameContainer = document.querySelector( '#iFrameContainer' );
var overlay = document.querySelector( '#overlay' );
if( iFrameContainer && overlay ){
overlay.addEventListener( 'click', function(){
console.log( 'Add event on Overlay' );
// We transfer the event click to the iframe
event.target.nextElementSibling.dispatchEvent( cloneMouseEvent( event ) );
} );
iFrameContainer.addEventListener( 'click', function(){
console.log( 'Click in IframeContainer' );
} );
}
function cloneMouseEvent( e ) {
var evt = document.createEvent( "MouseEvent" );
evt.initMouseEvent( e.type, e.canBubble, e.cancelable, e.view, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget );
return evt;
}
html:
<div style='position: relative; height:300px; width:300px;'>
<div id='overlay' style='width:100%; height:100%; margin-bottom: 20px; height: 100%; position: absolute; overflow: hidden; z-index: 10;'></div>
<div id='iFrameContainer' style="left: 0px; width: 100%; height: 100%; z-index:9;">
<iframe allowfullscreen="true" frameborder="0" mozallowfullscreen="true" src="//www.youtube.com/embed/wTcNtgA6gHs?feature=oembed " style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;" webkitallowfullscreen="true">
</iframe>
</div>
【问题讨论】:
-
你有没有尝试使用类似的插件:github.com/layalk/FlexSlider
-
实际上我现在使用github.com/thebird/Swipe 的重写版本作为swipper 我查看了您的插件,似乎他们遇到了同样的问题:flexslider.woothemes.com/video.html 在移动视图中查看此页面并尝试滑动vimeoh 视频不起作用。
标签: javascript iframe video swipe