[英]Floating navigation menu using Wordpress Twenty Eleven theme
我目前正在开发一个使用WordPress 21主题的网站,并且希望将主导航栏滚动到屏幕顶部之后,就像此页面右侧的段落http: //fiddle.jshell.net/zsJAr/show/light/ 。
到目前为止,我已经在标题中添加了代码,以在开始head标签之后添加jQuery:
<?php wp_enqueue_script("jquery"); ?>
后来我在关闭head标签之前加入了我的javascript:
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/moveScroller.js"></script>
moveScroller.js的内容为:
var $j = jQuery.noConflict();
$j(window).load(function(){
$j(function() {
var a = function() {
var b = $j(window).scrollTop();
var d = $j("#access-anchor").offset({scroll:false}).top;
var c=$j("#access");
if (b>d) {
c.css({position:"fixed",top:"0px"})
} else {
if (b<=d) {
c.css({position:"relative",top:""})
}
}
};
$j(window).scroll(a);a()
});
});
在以下块中进一步声明了“ access”和“ access-anchor” ID:
<div id="access-anchor"></div>
<nav id="access" role="navigation">
<h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav><!-- #access -->
这似乎没有任何作用,我也不十分确定该怎么做。 以使用WordPress的经验很少,我真的很感谢在此方面的一些帮助。 有谁知道如何解决这个问题?
如果您使用的是jQuery,还可以使滚动动画,看起来更有趣=)我在几周前使用了这段代码,它不使用固定位置,它使用margin-top,但是您可以轻松更改它:
var scroll = 0; //initially scroll is 0
var marginTop = 10; //we add an initial margin
$(window).scroll(function () {
//once the user scrolls, we calculate the new margin-top
marginTop = ($(document).scrollTop() - scroll) + marginTop;
//and we save the new amount of scroll, for the next time
scroll = $(document).scrollTop();
$("#divYouWantToMove").animate({"marginTop": marginTop+"px"}, {duration:500,queue:false} );
});
希望能帮助到你!
因此,似乎这不可能或太复杂了。 在WordPress Stack Exchange或WordPress论坛上没人知道这一点,因此我将不得不放弃:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.