javascript - Adding a fade in/fade out effect to innerHTML -


i have function loads in json file , changes contents of several divs on page. part works correct, wanted make sexy. when button calls function clicked, new text replaces old text. wanted old text fade out, change text, , fade in new text.

here code

function loadnextpassage()     {     //fading out effect     $("#passage-title").fadeout();     $("#title").fadeout();     $("#pre-post").fadeout();     $("#passage").fadeout();     $("#media").fadeout();      //load new json file , change elements     $.getjson("passage-2.3.2.json", function( data ) {      document.getelementbyid("passage-title").innerhtml = data["passagenumber"];     document.getelementbyid("title").innerhtml = data["title"];     document.getelementbyid("pre-post").innerhtml = data["prereading"];     document.getelementbyid("pre-reading-content").innerhtml = data["prereading"];     document.getelementbyid("post-reading-content").innerhtml = data["postreading"];     document.getelementbyid("passage").innerhtml = data["reading"];     document.getelementbyid("media").innerhtml = data["media"];      //fading elements in     $("#passage-title").fadein();     $("#title").fadein();     $("#pre-post").fadein();     $("#passage").fadein();     $("#media").fadein(); }); } 

i running problem when push button call function, code changes elements , fades out , in. hoping fade out text change elements , fade in. thank you!

the main problems:

  1. don't mix pure dom , jquery. use right tool you're doing, regardless of tools have available
  2. first fadeout() , in callback, change text , fadein().

snippet

$(function () {    $("button").click(function () {      $("p").fadeout(400, function () {        $(this).html("second one").fadein(400);      });    });  });
/* start praveen's reset fiddle ;) */  * {font-family: 'segoe ui'; margin: 0; padding: 0; list-style: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}  /* end praveen's reset fiddle ;) */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <button>next</button>  <p>first one</p>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -