改变标题背景在滚动在Wordpress二十四

Change header background on scroll in Wordpress Twenty Fourteen

本文关键字:Wordpress 二十四 滚动 改变 背景 标题      更新时间:2023-09-26

这是我希望在WP 2014主题中看到的结果:

http://codepen.io/Paulie-D/pen/ekKru

我试图通过添加以下js文件和css代码来应用相同的子主题:

jQuery(document).ready(function($){
  jQuery(window).bind('scroll', function($) {
    var distance = 50;
    if ($(window).scrollTop() > distance) {
      $('header').addClass('scrolled');
    }
    else {
      $('header').removeClass('scrolled');
    }
  });
});
.scrolled {
  background: #bada55;
}

此外,我还在子主题的functions.php中添加了以下内容:

function my_custommenu_tf_child() {
	if (!is_admin()) {
	if (is_front_page()) {
	wp_enqueue_script( 'my_Custommenu', get_stylesheet_directory_uri() . '/js/mycustommenu.js', '', '1.0', true );
	}
	}
}
add_action('wp_enqueue_scripts', 'my_custommenu_tf_child');

没有真正工作…我不是一个专业的开发人员,所以,而不是参考可能的解决方案,我会很感激,如果你能插入正确的代码,这样我就可以比较,看看到底是什么错了。谢谢!

.js文件中有以下代码吗?

.scrolled { background: #bada55; }

如果你有,你需要把它移动到一些.css文件,并将其链接到你的functions.php