我从头开始创建Wordpress网站。我有一个页面滚动到锚点的问题,如果它是单页 - 滚动正在使用#service
,但如果我的网站是主页我需要滚动和自定义页面,我不需要,我需要从自定义页面返回到我的主页,使用相同的菜单按钮和按下按钮的内容。我该如何解决?
我希望你理解我并感谢你的建议:)
有我的代码和照片:
//jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
$('.page-scroll a').bind('click', function(event) {
var $anchor = $(this);
var $anchor_scroll = $($anchor.attr('href')).offset().top;
var $anchor_scroll_calc = $anchor_scroll;
$('html, body').stop().animate({
scrollTop: $anchor_scroll_calc
}, 1500);
event.preventDefault();
});
});
我的标题菜单:
<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle collapse" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="#page-top">
<img id="#page-top" src="<?php echo get_template_directory_uri(); ?>/images/logo3.png" alt="Brand logo">
</a>
</div>
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 0,
'container' => 'div',
'container_class' => 'collapse navbar-collapse navbar-right navbar-main-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
<!-- Collect the nav links, forms, and other content for toggling -->
</div>
<!-- /.container -->
</nav>