2015-09-07 158 views
-1

我想在屏幕更改(完整/默認)上添加一個事件。給定的功能很好地工作在Chrome中,但不能在Firefox中工作。mozfullscreenchange不工作在Firefox中

if (myid.addEventListener){ 
    myid.addEventListener('webkitfullscreenchange' , changeScreen , false) 
    myid.addEventListener('mozfullscreenchange' , changeScreen , false) 
    myid.addEventListener('fullscreenchange' , changeScreen , false) 
    myid.addEventListener('MSwebkitfullscreenchange' , changeScreen , false) 
} 

else { 
    myid.attachEvent('fullscreenchange' , changeScreen) 
} 
function changeScreen(){ 
    if (mydiv.id != 'oldid') { 
     mydiv.id = 'oldid' 
    } 
    else { 
     mydiv.id = 'newid' 
    } 
} 

我該怎麼去錯了。請不要J查詢。只有JavaScript。

回答

1

'mozfullscreenchange'是包含元素的文檔事件(在這種情況下,我認爲'myid'是元素)。

所以,我認爲你可以修改代碼:

if (myid.addEventListener){ 
    myid.addEventListener('webkitfullscreenchange' , changeScreen , false) 
    document.addEventListener('mozfullscreenchange' , changeScreen , false) 
    myid.addEventListener('fullscreenchange' , changeScreen , false) 
    myid.addEventListener('MSwebkitfullscreenchange' , changeScreen , false) 
} 

您可以找到有關這個鏈接(通知部分) 'mozfullscreenchange' 的更多信息:https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API