0

每当我第一次点击卡片时,它都很顺利。但是每当卡片已经翻转时,我尝试单击返回以使其翻转,文本似乎消失了,但没有其他任何反应。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>flip cards</title>
    <style type="text/css">
        * {margin:0; padding:0;}            
        ul#cards li{list-style-type:none; margin:5px; }
        ul#cards img, #cards dl{width:200px; height:250px;background-color:orange;padding:5px;}
        ul#cards dl{display:none;}
        ul#cards dt{font-weight:bold;}

    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>   
    <script type="text/javascript">
        $(document).on("ready", geladen);
        function geladen(){
            console.log("geladen");
            $('#cards img').on("click", turn);
            $('#cards dl').on("click", turnBack);

        }
        function turn(event){
            $(event.target)
                .animate({"width":"0", "margin-left":"100"}, 500, 
                    function(){
                        $(this).css("display", "none")                  
                        .next()
                        .css("display", "block")
                        .animate({"width":"200", "margin-left":"0"}, 500);
                    }
                )
        }
        function turnBack(event){
            $(event.target)
                .animate({"width":"0", "margin-left":"100"}, 500)
                .css("display", "none")
                .prev()
                .css("display", "block")
                .animate({"width":"200", "margin-left":"0"}, 500);
        }
    </script>
</head>

<body>
    <ul id="cards">
        <li>
            <img src="wesley.jpg" alt="Wesley Sneijder, middenvelder" />
            <dl>
                <dt>naam</dt>
                <dd>Wesley Sneijder</dd>
                <dt>rol</dt>
                <dd>middenvelder</dd>
                <dt>geboortedatum</dt>
                <dd>9 juni 1984</dd>
                <dt>club</dt>
                <dd>Inter Milan</dd>
            </dl>
        </li>
        <li>
            <img src="robin.jpg" alt="Robin van Persie, aanvaller" />
            <dl>
                <dt>naam</dt>
                <dd>Robin van Persie</dd>
                <dt>rol</dt>
                <dd>aanvaller</dd>
                <dt>geboortedatum</dt>
                <dd>6 augustus 1983</dd>
                <dt>club</dt>
                <dd>Arsenal</dd>
            </dl>
        </li>
    </ul>
</body>

4

1 回答 1

1

尝试在 $(this) 而不是 $(event.Target) 上进行折返动画

    function turnBack(event){
        $(this)
            .animate({"width":"0", "margin-left":"100"}, 500)
            .css("display", "none")
            .prev()
            .css("display", "block")
            .animate({"width":"200", "margin-left":"0"}, 500);
    }

event.target 包含由于冒泡而实际单击的文本 (dt/dd),而 this 指的是附加单击的元素。

于 2012-07-03T08:47:35.353 回答