使用jquery创建quickview

时间:2012-07-28 13:05:28

标签: jquery html

我想为购物车创建快速浏览,

问题1:当我将鼠标放在任何一个方框上时,快速查看显示在所有方框中,如何只在父节点中显示它。

问题2:当我将鼠标放在quickview链接上时,它会继续切换。

这是我的代码

<html>
<title>Quick view </title>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style type="text/css">
.quickview{
    margin:0px;
    position:absolute;
    margin-top:18%;
    margin-left:12%;
    border:1px;
    border-color:red;
    border-style:dotted;
    display:none;
}

.box{
    margin:10px;
    height:300px;
    width:400px;
    border:2px;
    border-color:green;
    border-style:solid;
    background-color:silver;
}
</style>

<script type="text/javascript">
    $(document).ready(function(){
                $(".box").bind('mouseover',function(event){
                        $(".quickview").stop(true,true).fadeIn(100);
        });
                $(".box").bind('mouseleave', function(e) {
                        $(".quickview").stop(true,true).fadeOut(100);
        });
    });
        </script>

</script>
</head>
<body>
<div style="margin:10px;">
<table>
    <tr>
        <TD>
            <div class="quickview">
                <a href="doo.php">Quick View</a>
            </div>
            <div class="box">
                <a href="foo.php">

                </a>
            </div>
        </TD>
        <TD>
            <div class="quickview">
                <a href="doo.php">Quick View</a>
            </div>
            <div class="box">
                <a href="foo.php">

                </a>
            </div>
        </TD>
    </tr>
    <tr>
        <TD>
            <div class="quickview">
                <a href="doo.php">Quick View</a>
            </div>
            <div class="box">
                <a href="foo.php">

                </a>
            </div>
        </TD>
        <TD>
            <div class="quickview">
                <a href="doo.php">Quick View</a>
            </div>
            <div class="box">
                <a href="foo.php">

                </a>
            </div>
        </TD>
    </tr>
</table>
</div>

</body>
</html>

提前完成

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

 $(".box").bind('mouseenter',function(event){
     $(this).prev(".quickview").stop(true,true).fadeIn(100);
 }).parent().bind('mouseleave', function(e) {
     $(this).find(".quickview").stop(true,true).fadeOut(100);
 });​

demo