jQuery跨域iframe Mousemove功能

时间:2011-07-30 11:55:04

标签: jquery iframe vimeo mousemove

我正在开发项目,我正在使用代码嵌入vimeo视频FULLSCREEN:

<iframe id="iframe" src="http://player.vimeo.com/video/...../.." width="100%" height="100%" frameborder="0"></iframe> 

我在父页面上使用Mousemove功能在Mousemove上显示公司徽标,如下所示:

    $(document).ready(function() {
    var $top = $('#logo');
    var $document = $(document);
    var timer = null;
    var timerIsRunning = false;

    $top.hide();

    $document.mousemove(function(e){
    e.stopPropagation();
    });
    setTimeout(function() {
                    $document.mousemove(function(e) {
                            if($top.is(':hidden')) {
                                $top.fadeIn(2000);
                            } else {
                                if(!timerIsRunning) {
                                    timerIsRunning = true;
                                    clearTimeout(timer);
                                    timer = setTimeout(function() { $top.fadeOut();  }, 15000);
                                    setTimeout(function() {timerIsRunning = true;}, 15000);
                                }
                            }
                    });
            }, 2000);

});

我的问题是浏览器无法通过嵌入式全屏视频检测Mousemove功能。这就是Logo div没有出现的原因......

使用CSS pointer-events: none;它有效但禁用了视频播放器控制。

有解决方案吗?

由于

1 个答案:

答案 0 :(得分:0)

尝试在iframe中附加mousemove事件:

$(document).ready(function() {
    var $top = $('#logo');
    var $document = $(document);
    var timer = null;
    var timerIsRunning = false;

    $top.hide();

    $document.mousemove(function(e){
    e.stopPropagation();
    });
    setTimeout(function() {
                    $('#iframe',$document).mousemove(function(e) {
                            if($top.is(':hidden')) {
                                $top.fadeIn(2000);
                            } else {
                                if(!timerIsRunning) {
                                    timerIsRunning = true;
                                    clearTimeout(timer);
                                    timer = setTimeout(function() { $top.fadeOut();  }, 15000);
                                    setTimeout(function() {timerIsRunning = true;}, 15000);
                                }
                            }
                    });
            }, 2000);

    });