我想知道是否有人可以解释一下为什么它不能在ie8或9上工作,它在chrome和火狐上工作得很好。
下面是我的代码:
var image_src = {
middle: "background-position: 730px 0px;",
left: "background-position: 730px 480px;",
topleft: "background-position: 730px 960px",
top: "background-position:730px 1440px;",
topright: "background-position:730px 1920px;",
right: "background-position: 730px 2400px",
bottomright: "background-position: 730px 2880px;",
bottom: "background-position:730px 3360px;",
bottomleft: "background-position: 730px 3840px;"
};
var Hsection = $(document).width() / 3;
var Vsection = $(document).height() / 3;
console.log(Hsection);
console.log(Vsection);
$(document).mousemove(function(event){
var mloc = {
x: event.pageX,
y: event.pageY
};
// TOP ROW
if(
(mloc.x < Hsection) &&
(mloc.y < Vsection)
){
$(".tryme").attr("style", image_src.topleft);
}else if(
(mloc.x > Hsection && mloc.x < Hsection * 2) &&
(mloc.y < Vsection)
){
$(".tryme").attr("style", image_src.top);
}else if(
(mloc.x > Hsection * 2 && mloc.x < Hsection * 3) &&
(mloc.y < Vsection)
){
$(".tryme").attr("style", image_src.topright);
}
// MIDDLE ROW
else if(
(mloc.x < Hsection) &&
(mloc.y > Vsection && mloc.y < Vsection * 2)
){
$(".tryme").attr("style", image_src.left);
}else if(
(mloc.x > Hsection && mloc.x < Hsection * 2) &&
(mloc.y > Vsection && mloc.y < Vsection * 2)
){
$(".tryme").attr("style", image_src.middle);
}else if(
(mloc.x > Hsection * 2 && mloc.x < Hsection * 3) &&
(mloc.y > Vsection && mloc.y < Vsection * 2)
){
$(".tryme").attr("style", image_src.right);
}
// BOTTOM ROW
else if(
(mloc.x < Hsection) &&
(mloc.y > Vsection * 2 && mloc.y < Vsection * 3)
){
$(".tryme").attr("style", image_src.bottomleft);
}else if(
(mloc.x > Hsection && mloc.x < Hsection * 2) &&
(mloc.y > Vsection * 2 && mloc.y < Vsection * 3)
){
$(".tryme").attr("style", image_src.bottom);
}else if(
(mloc.x > Hsection * 2 && mloc.x < Hsection * 3) &&
(mloc.y > Vsection * 2 && mloc.y < Vsection * 3)
){
$(".tryme").attr("style", image_src.bottomright);
}
});下面是这段代码的demo。
发布于 2013-01-27 01:34:15
Internet explorer与console.log()不兼容...
if (typeof (console) !== "undefined"){
console.log(Hsection);
console.log(Vsection);
}http://jsfiddle.net/gkgHk/6/
https://stackoverflow.com/questions/14539503
复制相似问题