barbajs / barba

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

JavaScript file doesn't load after page transition #527

Closed Navajocoding closed 4 years ago

Navajocoding commented 4 years ago

Everything is working fine on my index.html. On the first .onload page all the images are draggable and all over the page

HERE THE PROBLEM:

However, when I WENT TO THE PAGE ABOUT.html AND GO BACK TO THE INDEX.html my script look like isn't working anymore and I can see only one image that is not even draggable anymore.

Have a closer look to my project here: https://codepen.io/cat999/project/editor/AEeEdg

everything work fine on first onload page and images are draggable but when i go to the about page and come back on the index page the draggable is not working

HOW DO I FIX ISSUE? COULD SOMEBODY HELP ME TO FIX MY CODE?

var winWidth = window.innerWidth,
    winHeight = window.innerHeight,
    threeWinHeight = winHeight*3;

$(window).on('resize', function(){
  winHeight = window.innerHeight,
  twiceWinHeight = winHeight*2;
});

$('.shape').each(function(){
  var topPos = Math.floor(Math.random()*1300),

      //BE CAREFUL 7000px is less then total body height or  CAUSING OVERFLOW
      leftPos = Math.floor(Math.random() * winWidth);
  $(this).css('top', topPos + 'px');
  $(this).css('left', leftPos + 'px');
});

Draggable.create('.shape', {
  //type:"rotation",
  bounds: '.section-2',
  edgeResistance:0.65,
  throwProps:true,
});

var number = Math.floor((Math.random() *15) + 2);
var number2 = Math.floor((Math.random() * 0) + -15);
var number3 = Math.floor((Math.random() * 0) + 15);
var number4 = Math.floor((Math.random() * 0) + 6);
$(".shape--circle").css("transform", "rotate(" + number2 + "deg)");
$(".shape--square").css("transform", "rotate(" + number3 + "deg)");
$(".shape--circle-2").css("transform", "rotate(" + number4 + "deg)");

Additionally, the index and the about section has using barba.js. Here the list of my script:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/utils/Draggable.min.js"></script>
<script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/ThrowPropsPlugin.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://unpkg.com/@barba/core"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.2.4/gsap.min.js"></script>
<script src="main.js"></script>
xavierfoucrier commented 4 years ago

Hi @Navajocoding,

This issue is more related to how your code is running than Barba v2 implementation...

For those kind of questions/help, please use the Slack workspace in order to ask the whole community for support. Join using the invite link here: https://barba.js.org/docs/getstarted/useful-links/#Developer

Anyway, I invite you to read the Views documentation section that will probably help you make your code run as expected.

I am closing the issue.