所以我有了这个网站,它是使用煎茶编辑器(煎茶动画师)创建的。
他们并不真正支持 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
});
那行得通,所以至少页面加载了它的所有内容。
现在我想用
$(element).click(function () {
alert('hello');
});
但这在 IE 或 Firefox 中根本不起作用(mouseup 也不起作用)(在这种情况下,IE 比 FF 更好)
我已经不知道了,整个 IE 的事情都打破了一切,而且一个只能在 Chrome 中运行的网站是不可能的......这真的很令人沮丧:P
该网站的链接可以在这里找到:链接
这是完整的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'
});
});`