Marlene, try adding the following JS code in your main.js file inside barba.init function:
views: [{
namespace: 'home-section',
beforeEnter({ next }) {
// load your script
let script = document.createElement('script');
script.src = 'draggable.js'; // location of your draggable js file that is responsible for that image loading and dragging functionality
next.container.appendChild(script);
},
}],
Marlene, you need to put this JS code below in a separate JS file and name it draggable.js for example and then insert a path to that JS file only into a script.src parameter that is stated in that code example above inside barba.init function.
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)");
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

** 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>
Thanks @timur would you be so kind to show me exatcly where I have to place the code inside my main.js? here the code