barbajs / barba

Create badass, fluid and smooth transitions between your website’s pages
https://barba.js.org/
MIT License
11.62k stars 474 forks source link

Execute javascript after page load #78

Closed kaspar-allenbach closed 8 years ago

kaspar-allenbach commented 8 years ago

Hi.

I'm learning javascript right now so I'm sorry if this is a stupid question:

I have this page: http://stage.aare.guru/

Its a very simple page, where the data is loaded trough a json and then bound to a ID within the html markup.How would I wove this into barba.js so my code still works?

I installed barba.js but if I just add Barba.Pjax.start(); of course my code dowsn't execute anymore. Which part of your doc's contains this?

I guess I have to wrap it somehow into the barba code:

var Homepage = Barba.BaseView.extend({
  namespace: 'homepage',
  onEnter: function() {
      // My Code right?
     $.ajax({
         url: "http://aareguru.existenz.ch/current.php",
         dataType: 'json',
         success: function( data ) {
              var currentReadable = moment.unix(currentUnix).format();
              $( "#nowUnix" ).text( currentUnix );
             //  and so on and so on
        }
     });
  },
});

Homepage.init();

That doesn't work. But I guess it should be something like this right?

luruke commented 8 years ago

Make sure that the data-namespace is correctly added to your .barba-container and that the namespace match the one you have in the barba view

kaspar-allenbach commented 8 years ago

Ahh. I mapped the namespace to the ID not the class. Thank you.