How to fade/blend between 2 divs in a less 'clunky' way

前端 未结 1 1900
梦如初夏
梦如初夏 2021-01-22 03:22

NB

My Header:

相关标签:
1条回答
  • 2021-01-22 03:43

    'Pleasing' is a very subjective term, however to improve it you could place both div elements within a parent container positioned absolutely so they overlap. You can then fadeToggle() between the two as needed. Something like this:

    $('#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>

    Click the text to see the fade transition in action.

    0 讨论(0)
提交回复
热议问题