在Web和JQuery的一些腳本的幫助下,我爲這個問題組裝了以下Javascript解決方案,並且它在所有瀏覽器上都能正常工作。
基於:http://adomas.org/javascript-mouse-wheel/
僅當鼠標進入容器div並重新啓用鼠標onMouseLeave
時禁用。
jQuery(function(){
$("#myFlashContainer").mouseenter(
function() {
if (window.addEventListener)
{
window.removeEventListener('DOMMouseScroll', wheelOn, false);
window.addEventListener('DOMMouseScroll', wheelOff, false);
}
/** IE/Opera. **/
window.onmousewheel = document.onmousewheel = wheelOff;
}
);
$("#myFlashContainer").mouseleave(
function() {
if (window.addEventListener)
{
window.removeEventListener('DOMMouseScroll', wheelOff, false);
window.addEventListener('DOMMouseScroll', wheelOn, false);
}
/** IE/Opera. **/
window.onmousewheel = document.onmousewheel = wheelOn;
}
);
function wheelOff(event)
{
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
} else if (event.detail) { /** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
// delta = -event.detail/3;
}
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
function wheelOn(event)
{
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
} else if (event.detail) { /** Mozilla case. */
// delta = -event.detail/3;
}
if (event.preventDefault)
{
//event.preventDefault();
event.returnValue = true;
}
return true;
}
});
這似乎在firefox/webkit中工作..但不是IE 8 ...也沒有將焦點設置爲.swf – Chris 2010-07-22 07:56:57