所以我有這個網站,它是使用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'
});
});`