Jquery秀隐藏

时间:2013-12-04 20:16:23

标签: jquery

我有这个代码,但我想在窗口加载时隐藏.test。 这是切换功能。我不给css。我希望这很容易,但我无法解决这个问题。

    <script>
$('#toggleDiv').toggle(function() {
    $('.test').delay(500).animate({
        'opacity': 0,
        'right': '-100%'
    });
    $(this).delay(1000).queue(function(n) {
        $(this).html('show');
        n();
    });
}, function() {
    $('.test').delay(500).animate({
        'opacity': 1,
        'right': '0%'
    });
    $(this).delay(1000).queue(function(n) {
        $(this).html('hide');
        n();
    });
}); 
    </script>

HTML

<pre>
<div id="toggleDiv">hide</div>
<div class="test">This secret has been passed down from generation to generation in our family and it reveals how to win a man’s heart.</div>
</pre>

4 个答案:

答案 0 :(得分:0)

尝试如下......它会帮助你......

<强> HTML:

<pre>
<div id="toggleDiv">show</div>
<div class="test">This secret has been passed down from generation to generation in our family and it reveals how to win a man’s heart.</div>
</pre>

<强> JQuery的:

$( ".test" ).toggle();
$("#toggleDiv").click(function(){
    if($("#toggleDiv").text() =="show")
    {
        $("#toggleDiv").text("hide");
    }
    else
        $("#toggleDiv").text("show");
      $( ".test" ).slideToggle( "slow" );
});

<强> CSS:

#toggleDiv { cursor: pointer; cursor: hand; }

小提琴: http://jsfiddle.net/2gD4Y/

如果您想滑动div信息,请尝试如下:

Jquery:

$(".test").hide();
$("#toggleDiv").click(function(){
    if($("#toggleDiv").text() =="show")
    {
        $("#toggleDiv").text("hide");
    }
    else
        $("#toggleDiv").text("show");
      $(".test").toggle("slide", {direction:'right'});
});

小提琴: http://jsfiddle.net/2gD4Y/1/

答案 1 :(得分:0)

尝试使用.hide().show()功能。

答案 2 :(得分:0)

$( document ).ready(function() {
   $(".test").hide();
});

答案 3 :(得分:0)

<script>
 $(document).ready(function(){
                   $("#toggleDiv").click(function(){
                   $("#test").toggle();
                   });
               });
</script>