English 中文(简体)
fadeIn/fade 点击另一碎片的指定干 d吗?
原标题:fadeIn/fadeOut specified div on click of another div?

I am creating something and I was wondering, if anyone can help me with one problem there. I have no ideas, how can I make a javascript that will always hide specified div id, and reveal it on a click of another div (for example an button). EDITED:

因此,我要说的是4个县。

<div class="section" id="info" style="margin-top: 0px; ">
<h3><a href="#">Button</a></h3>
</div>

<div class="section" id="search" style="margin-top: 0px; ">
<h3><a href="#">Button2</a></h3>
</div>

<div class="section" id="player" style="margin-top: 0px; ">
<h3><a href="#">Button3</a></h3>
</div>

<div class="section" id="socials" style="margin-top: 0px; ">
<h3><a href="#">Button4</a></h3>
</div>

现在我要说的是,我还有另一个小部分的内容,我想从上文点击第一个纽子。

    <div id="content-reveal">
    <p>something here</p>
    </div>

    <div id="content-reveal-2">
    <p>something here</p>
    </div>

    <div id="content-reveal-3">
    <p>something here</p>
    </div>

    <div id="content-reveal-4">
    <p>something here</p>
    </div>

Okay... 因此,已经确定了立场,所有立场都是正确的。

因此 我怎么能够隐藏<条码>与代号;div id=“大陆-reveal”>,并在有人点击我ton子时显示这一点?

www.un.org/spanish/ecosoc 我有4个有4个不同内容的县。 因此,在点击同一纽顿时,内容再次消失,在点击另一顿时,旧内容消失,新内容见。

简单问题,对我来说是艰巨的任务......

如果任何人能够提供帮助,我真心赞赏......

最佳回答

It seems like the other answers are not quite getting what the OP is looking for. From what I understand, the OP wants to:

  • Hide #content-reveal on page load
  • Fade-in #content-reveal when the button is pressed
  • No requirement to toggle #content-reveal (i.e., once it s displayed, it should stay displayed)

基于这一点,我的解决办法是:

$(document).ready( function() {
    $( #content-reveal ).hide();
    $( #show-button ).click( function() {
        $( #content-reveal ).fadeIn( 500 );
    } );
} );​

jsfiddle here: http://jsfiddle.net/xK83w/

EDIT:根据对欧佩斯问题的its,这里采取的做法是,你将努力做到:

$(document).ready( function() {
    $( #content-reveal ).hide();
    $( #info ).click( function() {
        $( #content-reveal ).fadeOut( 500, function() {
            $( #content-reveal ).html(  <b>info HTML</b>  );
            $( #content-reveal ).fadeIn( 500 );
        } );
    } );
    $( #search ).click( function() {
        $( #content-reveal ).fadeOut( 500, function() {
            $( #content-reveal ).html(  <b>search HTML</b>  );
            $( #content-reveal ).fadeIn( 500 );
        } );
    } );
    // repeat for  player  and  socials 
}

http://jsfiddle.net/xK83w/1/“rel=“nofollow” http://jsfiddle.net/xK83w/1/。

However, if your content blocks contain a lot of HTML, you may want to consider a different approach so you re not burdening your Javascript with a lot of HTML text. For example, you could have four different divs, and select between them like so:

<div id="content">

    <div id="content-reveal-info">
    <ul id="newsticker_1" class="newsticker">
        <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</li>
        <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip...</li>
        <li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum...</li>
        <li>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia...</li>
        <li>Bubble bubble ipsum dolor sit amet, consectetur adipisicing elit...</li>
    </ul>
</div>

<div id="content-reveal-search">
    <b>search HTML</b>
</div>

<div id="content-reveal-player">
    <b>player HTML</b>
</div>

<div id="content-reveal-socials">
    <b>socials HTML</b>
</div>

从而形成实际转换的功能:

var activeElement;

function activateElement( eltSuffix ) {
    if( activeElement ) {
        activeElement.fadeOut( 500, function() {
            activeElement = $( #content-reveal- +eltSuffix);
            activeElement.fadeIn( 500 );
        } );
    } else {
        activeElement = $( #content-reveal- +eltSuffix);
        activeElement.fadeIn( 500 );
    }
}

接着最后看看你的活动处理者:

$(document).ready( function() {
    $( #content div ).hide();
    $( #info ).click( function() {
        activateElement( info );
    } );
    $( #search ).click( function() {
        activateElement( search );
    } );
    $( #player ).click( function() {
        activateElement( player );
    } );
    $( #socials ).click( function() {
        activateElement( socials );
    } );
} );​

jsfiddle here: http://jsfiddle.net/xK83w/1/

问题回答
$( #info a ).on( click , function(evt) {
   evt.preventDefault();
   $( #newsticker_1 ).toggle();
});

服饰

$(document).ready(function(){
  $("#content-reveal").hide();
  $("#info").click(function(){
     $("#content-reveal").show();
   });

});

If you want to show/hide after every click then in place of $("#content-reveal").show(); write $("#content-reveal").toggle();

不要把你带往网页顶部,总是这样做。

<a href=“jaavascript:ave(0);”>Button</a>

这是JQuery,不是简单的javascript,但可以帮助你,请见

<div class="section" id="info" style="margin-top: 0px; ">
<h3><a href="#" id="showDiv" rel="hidden">Button</a></h3>
</div>
<div id="content-reveal">
    <ul id="newsticker_1" class="newsticker">
        <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</li>
        <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip...</li>
        <li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum...</li>
        <li>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia...</li>
        <li>Bubble bubble ipsum dolor sit amet, consectetur adipisicing elit...</li>
    </ul>
</div>

<script type="text/javascript">
$( #showDiv ).click(function(e){
   e.preventDefault();
   if($(this).attr( rel ) ==  hidden ){
      $( #content-reveal ).show();
      $(this).attr( rel ,  shown );
   }
   else
   {
      $( #content-reveal ).hide();
      $(this).attr( rel ,  hidden );
   }
}
</script>

当然,这样做还有其他不太容易和较小的方法,但是,如果看到你这样做的话,就会看到我迅速的移解,从而影响你们已经拥有的许多东西的总体概念。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签