How can I pause a jQuery on mouse hover iFrame object?

ε祈祈猫儿з 提交于 2019-12-12 04:48:41

问题


I have a jQuery that on mouse move it fade in/fade out a div object, however it doesn't work correctly when on view there is an iframe.

This is my jQuery:

var timer, myDiv = $('#mydiv');
$(document).on('mousemove', function(ev) {
    var _self = $(ev.target);

    clearTimeout(timer);

    if (_self.attr('id') === 'mydiv' || _self.parents('#mydiv').length) {
        return;
    }    

    if(!myDiv.hasClass('show')) {
       myDiv.fadeIn();
    }          

    timer = setTimeout(function() { 
        myDiv.fadeOut(1000, function() {
            myDiv.removeClass('show');
        });
    }, 1960);    
});

Why this jQuery doesn't work when the mouse pointer is hover an iframe object?

Here the DEMO

You can see on top of the demo page the proper functioning of the jQuery, it display the red square on mouse movement and hide it after n seconds of inactivity.

Instead if you try to do the same but on the iframe, the red square become hidden and nothing else.

UPDATE

Thanks to A. Wolff that shown me this I know that the solution is more complex than thought.

If the documents are not on the same document.domain it becomes quite a bit mroe complex, and you will need the iframes page to run javascript itself that sets the mousemove event listener. and then you can do cross frame communication as described here: http://softwareas.com/cross-domain-communication-with-iframes

The iFrame is referred to my subdomain page, so I can edit in any way needed.

How could I proceed?

来源:https://stackoverflow.com/questions/29680046/how-can-i-pause-a-jquery-on-mouse-hover-iframe-object

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