1

I have a slide mechanic that's working, but I am having problems getting the div class of nfooter to hide when the slide mechanic triggers. The slide is triggered when the user clicks on the img src question.png.

I would like for the nfooter (which is another image) to disappear when the user selects the question.png image. When the user selects the question.png image for the second time, the slide mechanic hides and the nfooter shows.

Again, the slide mechanic is working fine, I just can't get the nfooter and the question.png to play nice.

<pre>
<script type="text/javascript">

    // When the DOM is ready, initialize the scripts.
    jQuery(function( $ ){

    // Get a reference to the container.
    var container = $( ".container" );


    // Bind the link to toggle the slide.
    $( "a" ).click(
    function( event ){
    // Prevent the default event.
    event.preventDefault();

    // Toggle the slide based on its current
    // visibility.
    if (container.is( ":visible" )){

    // Hide - slide up.
    container.slideUp( 300 );

    } else {

    // Show - slide down.
    container.slideDown( 300 );

    }
    }
    );

    });

    </script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>

<body>
<a href="#"><img src="../question.png" /></a>
<div class="nfooter"></div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src='swipe.js'></script>

<div class='container'>
<div class='inner'>
    </div>
    </div>
</pre>
4

2 回答 2

2

您是否尝试过简单地隐藏和显示它:

if (container.is( ":visible" )){
    // Hide - slide up.
    container.slideUp(300, function(){ $('.nfooter').show(); });
}
else 
{
    // Show - slide down.
    container.slideDown(300, function(){ $('.nfooter').hide(); });
}
于 2013-09-05T05:32:07.217 回答
0

另一个版本

// When the DOM is ready, initialize the scripts.
jQuery(function($) {
    // Get a reference to the container.
    var container = $(".container"), nfooter = $('.nfooter');
    // Bind the link to toggle the slide.
    $("a").click(function(event) {
        event.preventDefault();

        var visibility = container.is(':visible');
        container.slideToggle(300);
        nfooter.toggle(visibility)
    });
});
于 2013-09-05T05:44:53.360 回答