jquery ui显示/隐藏在2次切换后停止工作

时间:2013-08-18 21:13:56

标签: jquery jquery-ui

我有一张图片 - 点击后会显示两个子div,然后在鼠标离开时隐藏它们。

这只能连续工作两次,然后停止点击。

$('.art').click(function(){
    var $this = $(this)

    $this.children('.details').children('div').eq(1).show("slide", {direction: "left", easing: "easeOutQuad"}, 200);
    $this.children('.details').children('div').eq(0).show("slide", {direction: "right", easing: "easeOutQuad"}, 200);

    $this.bind("mouseleave", function(){
        $this.children('.details').children('div').eq(0).hide("slide", {direction: "left", easing: "easeOutQuad"}, 200);
        $this.children('.details').children('div').eq(1).hide("slide", {direction: "right", easing: "easeOutQuad"}, 200);
    })
});

1 个答案:

答案 0 :(得分:1)

每次单击带有.art类的元素时,都会绑定到mouseleave。你能告诉我这是否有所改善:

$('.art').click(function(){
    var $this = $(this);

    $this.children('.details').children('div').eq(1).show("slide", {direction: "left", easing: "easeOutQuad"}, 200);
    $this.children('.details').children('div').eq(0).show("slide", {direction: "right", easing: "easeOutQuad"}, 200);
});

$('.art').mouseleave(function(){
    var $this = $(this)
    $this.children('.details').children('div').eq(0).hide("slide", {direction: "left", easing: "easeOutQuad"}, 200);
    $this.children('.details').children('div').eq(1).hide("slide", {direction: "right", easing: "easeOutQuad"}, 200);
    })