1

我想知道是否有人可以解释为什么它不能在 ie 8 或 9 上工作。它在 chrome 和 firefox 上工作得很好。

这是我的代码:

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);
            }

    });

这是此代码的演示

4

1 回答 1

2

Internet Explorer 与 console.log() 不兼容...

if (typeof (console) !== "undefined"){
console.log(Hsection);
console.log(Vsection);
}

http://jsfiddle.net/gkgHk/6/

于 2013-01-26T17:34:15.143 回答