我正在玩_S主题,试图让jQuery打开菜单,但单击时无响应。
控制台中没有错误消息,但是在页面加载时间歇性地弹出菜单。
应在单击.cd-nav-trigger
网站测试页在这里:test website
我已经将js文件放入了functions.php中,但是我认为我还必须拥有其他不太正确的东西。
有什么想法吗?
function new_script_manager() {
wp_enqueue_script('new_service', get_stylesheet_directory_uri() . '/js/modernizr.js', array(), false, true);
wp_enqueue_script('js_main', get_stylesheet_directory_uri() . '/js/main.js', array('jQuery'), false, true);
wp_register_style('my_style', get_template_directory_uri() . '/reset.css', array(), false, 'screen');
wp_enqueue_style('my_style');
wp_register_style('my_styles', get_template_directory_uri() . '/style.css', array(), false, 'screen');
wp_enqueue_style('my_styles');
}
add_action( 'wp_enqueue_scripts', 'new_script_manager' );
jQuery(document).ready(function($){
var isLateralNavAnimating = false;
//open/close lateral navigation
$('.cd-nav-trigger').on('click', function(event){
event.preventDefault();
//stop if nav animation is running
if( !isLateralNavAnimating ) {
if($(this).parents('.csstransitions').length > 0 ) isLateralNavAnimating = true;
$('body').toggleClass('navigation-is-open');
$('.cd-navigation-wrapper').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
//animation is over
isLateralNavAnimating = false;
});
}
});
});
<body>
<a href="#cd-nav" class="cd-nav-trigger">Menu
<span class="cd-nav-icon"></span>
<svg x="0px" y="0px" width="54px" height="54px" viewBox="0 0 54 54">
<circle fill="transparent" stroke="#656e79" stroke-width="1" cx="27" cy="27" r="25" stroke-dasharray="157 157" stroke-dashoffset="157"></circle>
</svg>
</a>
<div id="cd-nav" class="cd-nav">
<div class="cd-navigation-wrapper">
<div class="cd-half-block">
<h2>Navigation</h2>
<nav>
<ul class="cd-primary-nav">
<li><a href="#0" class="selected">The team</a></li>
<li><a href="#0">Our services</a></li>
<li><a href="#0">Our projects</a></li>
<li><a href="#0">Start a project</a></li>
<li><a href="#0">Contact us</a></li>
</ul>
</nav>
</div><!-- .cd-half-block -->
<div class="cd-half-block">
<address>
<ul class="cd-contact-info">
<li><a href="mailto:info@myemail.co">info@myemail.co</a></li>
<li>0244-12345678</li>
<li>
<span>MyStreetName 24</span>
<span>W1234X</span>
<span>London, UK</span>
</li>
</ul>
</address>
</div> <!-- .cd-half-block -->
</div> <!-- .cd-navigation-wrapper -->
</div> <!-- .cd-nav -->
</body>