首先,我对Javascript毫无希望,也不了解JSON。
我目前正在构建一个网站,并将 particles.js 纳入设计中。然而,在搜索了几天之后,我无法将get_stylesheet_directory_uri()函数调用到JSON配置文件中。
我能够通过在header.php文件中全局声明一个js变量来弄清楚如何在particle.js和particles-app.js中做到这一点,但对于JSON,我不知道。
这是我需要称之为的地方:
"image": {
"src": "sprites/blueBlur.png",
"width": 100,
"height": 100
}
如果我保持原样,它只指向根Wordpress文件。
整个JSON文件是:
{
"particles": {
"number": {
"value": 43,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#00ffd8"
},
"shape": {
"type": "image",
"stroke": {
"width": 0,
"color": "#000"
},
"polygon": {
"nb_sides": 6
},
"image": {
"src": "sprites/blueBlur.png",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 1,
"random": true,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 2,
"random": false,
"anim": {
"enable": true,
"speed": 10,
"size_min": 40,
"sync": false
}
},
"line_linked": {
"enable": false,
"distance": 200,
"color": "#ffffff",
"opacity": 1,
"width": 2
},
"move": {
"enable": true,
"speed": 1.9,
"direction": "none",
"random": true,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": false,
"mode": "grab"
},
"onclick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
}
此致 迈克尔
答案 0 :(得分:0)
由于url被分配给头中的全局JS变量,你可以像这样在JSON对象中调用/附加它。
var url = 'http://example.com/wp-content/themes/twentysixteen';
var json = {
"image": {
"src": url + "sprites/blueBlur.png",
"width": 100,
"height": 100
}
};
console.log(json);
答案 1 :(得分:0)
您可以使用PHP来使用样式表的直接网址。
像
<?php echo $_SERVER['SERVER_NAME']; ?>/wp-content/themes/your_theme/style_directory/file.css
可能会对你有帮助。