所以我有这个网站,它是使用sencha编辑器(Sencha Animator)创建的。Internet Explorer 8.事件
他们并不真的支持IE,所以我决定自定义编辑它,因为我们的大多数客户仍然使用IE7 +。
现在的主要问题是,它在Chrome,Safari,FF和IE8/9中加载正常。但是没有一个事件似乎可行。
我第一次尝试做一些条件检查(我发现这里),看看它是什么样的浏览器,并添加类似的事件:
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener){
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent){
el.attachEvent("on"+eventName, eventHandler);
}
}
不知怎的,这段代码突然崩裂上
if (el.addEventListener) {
所以之后,我认为等待,jQuery应该有这个内置的。 所以我从谷歌添加jQuery的CDN。
在我的JS我加了
$(document).ready(function() {
// load my start function here
});
这样的作品,所以ATLEAST所有的页面加载它的内容。
现在我想用
$(element).click(function() {
alert('hello');
});
但是,这并不在所有在IE火狐也没有(IE更好地工作,然后FF在这种情况下)
工作(也没有鼠标松开这个问题)我没有线索了,这整个IE浏览器的东西都打破了一切,而一个只能在Chrome中运行的网站是不可能的......这真的很令人沮丧:P
链接到网站可以在这里找到: Link
下面是完整的JS代码:
if (typeof (AN) === 'undefined') {
AN = {};
}
AN.Controller = {
scenes: {},
scenesArray: [],
currentSceneID: -1,
olElement: null,
events: {},
useOrmma: false,
setConfig: function (configData) {
this.events = configData.events;
this.olElement = document.getElementById(configData.parentId);
var liElements = this.olElement.children;
if (configData.ormma) {
this.useOrmma = true;
}
var scene;
for (var i = 0; i < configData.scenes.length; i++) {
scene = configData.scenes[i];
scene.element = liElements[i];
this.scenes[scene.id] = scene;
this.scenesArray.push(scene);
}
this.setupListeners();
this.startSceneByID(this.scenesArray[0].id);
},
runningAnimationCount: 0,
browser: 'webkit',
setupListeners: function() {
var me = this;
var eventName = "webkitAnimationEnd";
if (document.body.style.MozAnimationName !== undefined) {
eventName = "animationend";
this.browser = "moz";
}
function addMousemoveListenerTo(scene) {
/*bindEvent(scene.element, 'mousemove', function (event) {
scene.mousemoveAction(me, event);
}, false);*/
}
var scene;
for (var i = 0; i < this.scenesArray.length; i++) {
scene = this.scenesArray[i];
if (scene.mousemoveAction) {
addMousemoveListenerTo(scene);
}
}
function addListenerTo(element, eventType, aFunction) {
/*bindEvent(element, eventType, function (event) {
aFunction(me, event);
});*/
$("#AN-sObj-17984").live("click", function(){
AN.Controller.startSceneByID(2);
});
}
var element, event;
for (var i = 0; i < this.events.length; i++) {
event = this.events[i];
element = document.getElementById(event.id);
addListenerTo(element, event.type, event.handler);
}
},
onAnimationEnd: function() {
this.runningAnimationCount--;
if (this.runningAnimationCount === 0) {
this.onSceneFinish();
}
},
startSceneByID: function (sceneID) {
var me = this;
if (sceneID === this.currentSceneID) {
this.scenes[sceneID].element.setAttribute('class', 'run restart');
setTimeout(function() {
me.runningAnimationCount = me.scenes[sceneID].animationCount;
me.scenes[sceneID].element.setAttribute('class', 'run');
if (me.scenes[sceneID].startAction) {
me.scenes[sceneID].startAction(me);
}
if (me.scenes[sceneID].animationCount === 0) {
me.onSceneFinish();
}
}, 0);
return;
} else if (this.currentSceneID !== -1) {
this.scenes[this.currentSceneID].element.setAttribute('class', '');
}
this.runningAnimationCount = this.scenes[sceneID].animationCount;
this.currentSceneID = sceneID;
var nextScene = this.scenes[sceneID];
if (this.browser === 'moz') {
nextScene.element.setAttribute('class', 'run restart');
var unused = nextScene.element.offsetHeight;
nextScene.element.setAttribute('class', 'run');
} else {
console.log(nextScene.element);
nextScene.element.setAttribute('class', 'run');
}
if (this.useOrmma) {
this.ormmaNextScene(nextScene);
}
if (nextScene.startAction) {
nextScene.startAction(this);
}
if (nextScene.animationCount === 0) {
this.onSceneFinish();
}
},
replayScene: function() {
this.startSceneByID(this.currentSceneID);
},
onSceneFinish: function() {
if (this.scenes[this.currentSceneID].endAction) {
this.scenes[this.currentSceneID].endAction(this);
}
},
goToNextScene: function() {
var nextIndex = this.scenesArray.indexOf(this.scenes[this.currentSceneID]) + 1;
var nextScene;
if (nextScene = this.scenesArray[nextIndex]) {
this.startSceneByID(nextScene.id);
}
},
goToURL: function (aURL) {
document.location.href = aURL;
},
ormmaNextScene: function (nextScene) {
var currentState = ormma.getState();
if (nextScene.dimensions.expanded) {
var maxSize = ormma.getMaxSize();
if (currentState !== 'expanded') {
ormma.expand({
x: 0,
y: 0,
width: maxSize.width,
height: maxSize.height
});
}
var transform = "";
var elementHeight = nextScene.element.offsetHeight;
var elementWidth = nextScene.element.offsetWidth;
var y = (maxSize.height - elementHeight)/2;
var x = (maxSize.width - elementWidth)/2;
transform += " translate3d(" + Math.round(x) + "px," + Math.round(y) + "px,0)";
if (nextScene.dimensions.fit) {
var scaleFactor = Math.min(maxSize.width/elementWidth, maxSize.height/elementHeight);
transform += " scale3d(" + scaleFactor + "," + scaleFactor + ",1)";
}
nextScene.element.style.webkitTransform = transform;
} else {
if (currentState === 'expanded') {
ormma.close();
}
ormma.resize(nextScene.dimensions.width, nextScene.dimensions.height);
}
}
};
function loadData() {
var configData = {
parentId: 'AN-sObj-parentOl',
ormma: false,
scenes: [//lots of config data
]
};
AN.Controller.setConfig(configData);
};
$(document).ready(function() {
loadData();
$("area[rel^='prettyPhoto']").prettyPhoto({
social_tools: '',
show_title: false,
theme: 'light_rounded'
});
});`