NB

我的标题:

<header>
    <div style="float:left;margin-left:20px;">
       <div style="float:left; margin-left:10px;margin-top:55px;background-color:#2BC3A7; height:3px; width:200px;">&nbsp;</div>
        <div style="clear:both;float:left;"></div>
        <div style="float:left; margin-left:10px;margin-top:5px;font-family:DIN; font-size:12pt;color:#2BC3A7;">Services/Products</div>
    </div>
    </div>
</header>


我有2个div:

<div id="#content1">
    <div id="divWelcome" style="margin-top:50px;">
        <div id="headerimg" style="position: relative;">
            <div style="position: absolute; bottom:255px; left: 20px; width: 550px; font-family:DIN; font-size:23pt; font-weight:600; color: white; letter-spacing:0.01em;">
                We offer Cloud solutions for small businesses to help them manage their workflow requirements
            </div>

            <hr style="height:6px;position: absolute; bottom:210px; left: 20px; width: 490px;"/>


            <div style="position: absolute; bottom:175px; left: 20px; width: 550px; font-family:DIN; font-size:14pt; font-weight:500; color: white; letter-spacing:0.01em;">
               Our core sectors of expertise are professional services, data management and outsourcing.
            </div>

        </div>


        <div id="divAboutContents" style="margin-top:50px; background-color:red;position: relative;display: none;">
            &nbsp;
        </div>
     </div>
</div>


因此,当页面加载时,显示第一个div。我想要的效果是,当用户按下按钮时,divFirst会逐渐消失,而divSecond会逐渐消失。

<script type="text/javascript">
    $(document).ready(function () {
        $("#divAbout").click(function () {
            $("#headerimg").fadeOut();
            $("#divAboutContents").fadeIn();
        });
    });
</script>


我还能尝试/阅读什么?谢谢

NB
这是我的CSS的一部分

#content1 {
    clear: both;
    position: absolute;
}


我也正在淡出另一个。只是忘了把它放在问题中了。我得到的影响是“笨拙的”

最佳答案

“取悦”是一个非常主观的术语,但是要改进它,您可以将两个div元素放置在一个绝对放置的父容器中,以便它们重叠。然后,您可以根据需要在两者之间fadeToggle()。像这样:



$('#container').click(function() {
  $(this).find('div').fadeToggle();
})

#container > div {
  position: absolute;
}
#divSecond {
  display: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="container">
  <div id="divFirst">some content with images</div>
  <div id="divSecond">different content with images</div>
</div>





单击文本以查看渐变效果。

10-06 04:47