Javascript Smoothstate.js-通过functions.php加载特定样式表和脚本不起作用
我想知道是否有人能帮我。我目前正在使用Smoothstate.js插件在我的Wordpress网站上的页面之间进行转换。到目前为止,这个插件工作得很好,完成了我希望它完成的大部分工作 但是,当我尝试通过Wordpress中的functions.php文件为各个页面加载单独的文件时,当我在页面之间导航时,一些脚本无法工作 我已确保将脚本加载到容器中,以便Smoothstate.js知道添加了哪些文件,并且还使用onAfter函数重新初始化了函数 这很奇怪,因为当我在浏览页面后检查DOM时,我可以看到正在加载的脚本,但是如果我检查开发工具中的sources选项卡,它们不会出现 出于性能原因,我需要能够根据您所处的页面专门加载单独的文件,所以我希望有一种方法可以做到这一点,而不会与Smoothstate.js冲突。有人对此有经验或知道答案吗 我的设置如下: Functions.php 正如你所看到的,我只想在联系人页面上加载谷歌地图Javascript Smoothstate.js-通过functions.php加载特定样式表和脚本不起作用,javascript,php,ajax,wordpress,smoothstate.js,Javascript,Php,Ajax,Wordpress,Smoothstate.js,我想知道是否有人能帮我。我目前正在使用Smoothstate.js插件在我的Wordpress网站上的页面之间进行转换。到目前为止,这个插件工作得很好,完成了我希望它完成的大部分工作 但是,当我尝试通过Wordpress中的functions.php文件为各个页面加载单独的文件时,当我在页面之间导航时,一些脚本无法工作 我已确保将脚本加载到容器中,以便Smoothstate.js知道添加了哪些文件,并且还使用onAfter函数重新初始化了函数 这很奇怪,因为当我在浏览页面后检查DOM时,我可以看
wp_enqueue_script( 'anime-script', get_stylesheet_directory_uri() . '/js/anime.min.js', array(), $the_theme->get( 'Version' ), true);
wp_enqueue_script( 'scrollMonitor-script', get_stylesheet_directory_uri() . '/js/scrollMonitor.js', array(), $the_theme->get( 'Version' ), true);
wp_enqueue_script( 'scroll-scripts', get_stylesheet_directory_uri() . '/js/scrollreveal.js', array(), $the_theme->get( 'Version' ), true );
wp_enqueue_script( 'type-script', get_stylesheet_directory_uri() . '/js/typed.min.js', array(), $the_theme->get( 'Version' ), true);
if(is_page('contact-us')) {
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyC5_sL4wf3GIEgwI7bUXWD4pqkkc8er7tQ', array(), $the_theme->get('Version'), true);
wp_enqueue_script( 'google-maps-settings', get_stylesheet_directory_uri() . '/js/google-maps.js', array(), $the_theme->get( 'Version' ), true);
wp_enqueue_script( 'contact-slider', get_stylesheet_directory_uri() . '/js/contact-slider.js', array(), $the_theme->get( 'Version' ), true);
}
Smoothstate js
$(document).ready(function() {
init();
});
function init() {
ImageSliders();
navbarColour();
typedBanners();
scrollingAnimations();
navBarHide();
animateOnLoadPosition();
openSubscribePanel();
};
$(document).ready(function() {
'use strict';
addBlacklistClass();
// Init here.
var $body = $('body'),
$main = $('#page'),
$site = $('html, body'),
transition = 'fade'
var options = {
prefetch: true,
cacheLength: 2,
debug: true,
blacklist: '.wp-link, .open-panel-link',
onBefore: function($anchor, $container) {
var current = $('[data-viewport]').first().data('viewport'),
target = $anchor.data('target');
current = current ? current : 0;
target = target ? target : 0;
if (current === target) {
transition = 'fade';
} else if (current < target) {
transition = 'grow';
} else {
transition = 'moveleft';
}
var highResImageUrl = $anchor.find('.thumbnail-holder').data('src');
var thumbnailholder = $anchor.find('.thumbnail-holder');
var newImage = $anchor.closest('.thumbnail-wrapper').append('<img class="imageGrow" src="' + highResImageUrl + '">');
},
onStart: {
duration: 1200, // Duration of our animation
render: function (url, $container) {
// Add your CSS animation reversing class
$main.attr('data-transition', transition);
$main.addClass('is-exiting');
// Restart your animation
smoothState.restartCSSAnimations();
}
},
onReady: {
duration: 0,
render: function ($container, $newContent) {
// Remove your CSS animation reversing class
$container.removeClass('is-exiting');
// Inject the new content
$container.html($newContent);
}
},
onAfter: function() {
init();
addBlacklistClass();
if (typeof contactSliderUI == 'function') {
contactSliderUI();
}
$('.acf-map').each(function() {
// create map
map = new_map( $(this) );
});
var $hash = $( window.location.hash );
if ( $hash.length !== 0 ) {
var offsetTop = $hash.offset().top;
$( 'body, html' ).animate( {
scrollTop: ( offsetTop - 60 ),
}, {
duration: 280
} );
}
}
},
smoothState = $('#page').smoothState(options).data('smoothState');
});
$(文档).ready(函数(){
init();
});
函数init(){
图像滑块();
navbarcolor();
typedBanners();
滚动动画();
navBarHide();
动画加载位置();
openSubscribePanel();
};
$(文档).ready(函数(){
"严格使用",;
addBlacklistClass();
//在这里初始化。
变量$body=$('body'),
$main=$(“#页”),
$site=$('html,body'),
过渡=‘淡入’
变量选项={
预回迁:对,
缓存长度:2,
是的,
黑名单:'.wp链接,.打开面板链接',
onBefore:function($anchor,$container){
var current=$(“[数据视口]”).first().data(“视口”),
target=$anchor.data('target');
电流=电流?电流:0;
目标=目标?目标:0;
如果(当前===目标){
过渡=‘褪色’;
}否则如果(当前<目标){
过渡=‘增长’;
}否则{
转换='moveleft';
}
var highResImageUrl=$anchor.find('.thumbnail holder').data('src');
var thumbnailholder=$anchor.find('.thumbnailholder');
var newImage=$anchor.closest('.thumbnail wrapper').append('');
},
启动:{
持续时间:1200,//我们动画的持续时间
呈现:函数(url$container){
//添加CSS动画类
$main.attr('data-transition',transition);
$main.addClass('is-exiting');
//重新启动动画
smoothState.restartsAnimations();
}
},
onReady:{
持续时间:0,
呈现:函数($container,$newContent){
//删除CSS动画类
$container.removeClass('is-exiting');
//注入新内容
$container.html($newContent);
}
},
onAfter:function(){
init();
addBlacklistClass();
如果(contactSliderUI的类型=='function'){
contactSliderUI();
}
$('.acf map')。每个(函数(){
//创建地图
map=new_map($(this));
});
var$hash=$(window.location.hash);
如果($hash.length!==0){
var offsetTop=$hash.offset().top;
$('body,html')。动画({
scrollTop:(偏置-60),
}, {
持续时间:280
} );
}
}
},
smoothState=$(“#页”).smoothState(选项).data('smoothState');
});
您需要将
添加到您的容器或容器中的另一个元素(m-scene)。
Smoothstate只处理容器中的内容,除非元素位于“m-scene”容器中,否则您的
元素上的类不会更改。您好,我想知道,如何确保脚本加载到容器中?使用排队功能,我们只能在页眉或页脚中加载它们,对吗?