这里的问题:
https://i.stack.imgur.com/AMOLF.gif
我的 index.html 上一切正常。在第一个 .onload 页面上,所有图像都是可拖动的并且遍布整个页面。但是,当我转到 ABOUT.html 页面并返回 INDEX.html 时,我的脚本看起来不再工作了,我只能看到一个甚至无法拖动的图像。
我的项目在这里: https ://codepen.io/cat999/project/editor/AEeEdg
如何解决问题?有人可以帮我修复我的代码吗?
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)");
我尝试在 barba.init 函数内的 main.js 文件中添加以下 JS 代码,但没有奏效:
views: [{
namespace: 'home-section',
beforeEnter({ next }) {
// load script
let script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenMax.min.js';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/utils/Draggable.min.js';
script.src = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/ThrowPropsPlugin.min.js'; // location of your draggable js file that is responsible for that image loading and dragging functionality
next.container.appendChild(script);
},
}],
`````
[1]: https://i.stack.imgur.com/AMOlF.gif