javascript - Fade between DIVS -
trying make fading effect between multiple divs. not working, please can me "im new in javascript"
demo generate code.
in demo code work when copy code, stop working.
hope question clear ! thanks
code try copy.
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script> txt1 = $("#contentarea-1").text(); txt2 = $("#contentarea-2").text(); $("#pg1").on('click', function () { $('#contentarea-2').hide(); $('#contentarea-1').fadeout(500, function () { $("#contentarea-1").hide(txt2); $('#contentarea-1').fadein(500); }); }); $("#pg2").on('click', function () { $('#contentarea-1').hide(); $('#contentarea-2').fadeout(500, function () { $("#contentarea-2").text(txt2); $('#contentarea-2').fadein(500); }); }); </script> <style> #content-wrapper{ margin-left: 50px; } #contentarea-1{ width: 450px; } #contentarea-2{ width: 450px; display:none; } #clear{ clear: both; } nav{ text-align: center; } nav ul{ list-style: none; } nav ul li{ display: inline-block; padding: 15px; } </style> <nav> <ul> <li><a href="#1" id="pg1">page 1</a></li> <li><a href="#2" id="pg2">page 2</a></li> </ul> </nav> <div id="content-wrapper"> <div id="contentarea-1"> <wbr><p>first page</p></wbr> </div> <div id="contentarea-2"> <wbr><p> second page</p></wbr> </div> <div id="clear"></div> </div>
there's slight change required. forgot wrap javascript in jquery domready
container:
<script> $(function() { txt1 = $("#contentarea-1").text(); txt2 = $("#contentarea-2").text(); $("#pg1").on('click', function () { $('#contentarea-2').hide(); $('#contentarea-1').fadeout(500, function () { $("#contentarea-1").hide(txt2); $('#contentarea-1').fadein(500); }); }); $("#pg2").on('click', function () { $('#contentarea-1').hide(); $('#contentarea-2').fadeout(500, function () { $("#contentarea-2").text(txt2); $('#contentarea-2').fadein(500); }); }); }); </script>
Comments
Post a Comment