悬停时图像放大,但鼠标输出时垂直图像不恢复正常

时间:2012-10-29 13:39:15

标签: jquery

水平图像放大并恢复正常但垂直图像放大然后返回水平而不是垂直。我有this fiddle。我不确定,但相信问题出在jQuery中。我对jQuery很新,但这似乎是实现我需要的唯一方法,因为每个图像也是一个表单提交按钮。这可以在www.starcuts10.com/poems上看到

CSS:

#container {
    display: block;
    width: 100%;
    position: relative;
}

.img {
    position: relative;
    z-index: 0;
}

.end {
    margin-right: 0;
}

.clear {
    clear: both;
}

.img a img {
    position: relative;
    border: 0 solid #fff;
 }

.form_align {
    display: inline;
    float: left:
}

jQuery的:

$(document).ready(function() {
    var cont_left = $("#container").position().right;

    if ($('span').hasClass('horz')) {
        $("input").hover(function() {
            // hover in
            $(this).parent().parent().css("z-index", 1);
            $(this).animate({
                height: "405",
                width: "638",
                right: "+=50",
                bottom: "+=150"
            }, "fast");
        }, 
        function() {
            // hover out
            $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "250",
                width: "425",
                right: "-=50",
                bottom: "-=150"
            }, "fast");
        });


        $(".img").each(function(index) {
            var right = (index * 160) + cont_left;
            $(this).css("right", right + "px");
        });
    } 
    else {
        $("input").hover(function() {
            // hover in
            $(this).parent().parent().css("z-index", 1);
            $(this).animate({
                height: "638",
                width: "405",
                right: "+=50",
                bottom: "+=150"
            }, "fast");
        }, 
        function() {
            // hover out
            $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "425",
                width: "250",
                right: "-=50",
                bottom: "-=150"
            }, "fast");
        });

        $(".img").each(function(index) {
            var right = (index * 160) + cont_left;
            $(this).css("right", right + "px");
        });
    }
});

HTML:

<div id="container">
    <table>
        <tr>
            <span class="horz">
                <span class="vert">    
                    <td>
                        <form class="form_align" method ="post" action="#">
                            <a href=""><input type="image" src="http://starcuts10.com/images/blue_box.png" class="img"></a>
                            <input type="hidden" name="img" value="http://starcuts10.com/images/blue_box.png"> 
                            <input type="hidden" name="poem" value="">
                        </form>
                    </td>
                </span>
                <span class="vert">    
                <td>
                    <form class="form_align" method ="post" action="#">
                        <a href=""><input type="image" src="http://starcuts10.com/images/red_box.png" class="img"></a>
                        <input type="hidden" name="img" value="http://starcuts10.com/images/red_box.png"> 
                        <input type="hidden" name="poem" value="">
                    </form>
                </td>
            </span>  
        </tr>
    </table><br><br><br>
</div>

1 个答案:

答案 0 :(得分:0)

你的jquery逻辑有问题。

您不需要if ("span.horz") { .. } else { .. }

您需要做的是对$(".horz input")$(".vert input")都有悬停效果。

另外,html是错误的。跨度应该在TDs内部

这是一个工作小提琴:http://jsfiddle.net/RwJhn/1/

相关问题