jQuery Transition仅适用于Chrome

时间:2013-05-23 14:18:15

标签: jquery css

首先,我对jQuery完全不熟悉(我更像是桌面应用开发者)

我正在尝试构建我的第一个jQuery代码,它包含3 DIV之间的“滑动”过渡效果。

我无法弄清楚为什么它只适用于Chrome,而不适用于FF或IE。 第一个和第二个都不想移动或隐藏。

非常感谢任何有关此问题的帮助,感谢提前!

这是我目前的代码:

jQuery:

$(function () {

    var contentWidth = '-' + ($('.content').width() + 1000) + 'px';

    $('.content').css({
        position: 'absolute',
        left: contentWidth
    });    

    $('#ligne1')
        .animate({ left: 100 },"fast")
        .addClass('visible');

    $("a.temp").click(function () {
        event.preventDefault();
        var $blockID = $( $(this).attr('href') );
        if ($blockID.hasClass('visible')) { return; }
        $('.content.visible')
            .removeClass('visible')
            .animate( { left: $(window).width() }, function () {
                $(this).css('left', contentWidth);
            });
        $blockID
            .addClass('visible')
            .animate({ left: 100 }, 1000);
    });
});

这是我的CSS:

.wrapper { position: relative;}
.content { width: 900px; height: 300px; padding: 0; left: 0; top: 0; }
.box { width: 900px; height: 300px; }
#ligne1 .box { background: green; }
#ligne2 .box { background: yellow; }
#ligne3 .box { background: red; }

最后这是我的HTML:

<a class="temp" href="#ligne1">One</a>
<a class="temp" href="#ligne2">Two</a>
<a class="temp" href="#ligne3">Three</a>
<div class="wrapper" style="style="position: absolute; left: 50%; ">
    <div id="ligne1" class="content">
        <div class="box"></div>
    </div>
    <div id="ligne2" class="content">
        <div class="box"></div>
    </div>
    <div id="ligne3" class="content">
        <div class="box"></div>
    </div>
</div>

1 个答案:

答案 0 :(得分:3)

您需要将事件对象传递到Click处理程序:

$("a.temp").click(function (event) {...}

这是来自FF中的Firebug控制台的错误:

  

ReferenceError:未定义事件