小标
2018-08-06
来源 :
阅读 1788
评论 0
摘要:本文主要向大家介绍了Flash基础入门之关于flash的mousewheel事件,通过具体的内容向大家展现,希望对大家学习Flash基础入门有所帮助。
本文主要向大家介绍了Flash基础入门之关于flash的mousewheel事件,通过具体的内容向大家展现,希望对大家学习Flash基础入门有所帮助。
flash在wmode为opaque或transparent时,AS编写的鼠标滚轮事件失效。在此情况下,只能通过外部的JS实现事件绑定。我的实现代码如下:(已通过firefox,chrome,IE8测试)
function registMousewheel(id){
function _onmousewheel(e) {
var target = e.srcElement || e.target;
if(mousewheelHandler.containsTarget(target)){
var delta = 0;
if(e.wheelDelta ){
delta = e.wheelDelta / 120;
}else if(e.detail){
delta = -e.detail;
}
if (delta != 0) {
target.mousewheelHandler && target.mousewheelHandler(delta);
}
e.preventDefault && e.preventDefault();
}
return false;
}
if (typeof mousewheelHandler == "undefined") {
var _mousewheelHandler = {
targets:{},
containsTarget:function(target){
return target.id in this.targets;
},
regist:function(el) {
if(typeof el=="string"){
el = document.getElementById(el);
}
if (el == null) return;
this.targets[el.id] = el;
if(typeof window.attachEvent!="undefined"){
document.attachEvent("onmousewheel",_onmousewheel);
}else if(typeof window.addEventListener!="undefined"){
document.addEventListener("DOMMouseScroll",_onmousewheel,false);
document.addEventListener("mousewheel",_onmousewheel,false);
}
},
unregistAll:function(){
if(typeof window.attachEvent!="undefined"){
document.detachEvent("onmousewheel",_onmousewheel);
}else if(typeof window.addEventListener!="undefined"){
document.removeEventListener("DOMMouseScroll",_onmousewheel,false);
document.removeEventListener("mousewheel",_onmousewheel,false);
}
this.targets = {};
}
};
mousewheelHandler = _mousewheelHandler;
}
mousewheelHandler.regist(id);
}
可以将上面的JS代码写在AS脚本中,当flash加载完成时直接调用。
值得注意的是,DOMMouseScroll只适用于firefox且只能绑定在document上。
最后,比较容易犯错的一点,flash提供的回调函数名称一定不要与事件名称相同,如onmousewheel,onclick等,这样在IE下会提示找不到方法的错误,切记!
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标常用软件Flash频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号