Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Wordpress Twenty-Eleven主题的浮动导航菜单_Php_Javascript_Jquery_Css_Wordpress - Fatal编程技术网

Php 使用Wordpress Twenty-Eleven主题的浮动导航菜单

Php 使用Wordpress Twenty-Eleven主题的浮动导航菜单,php,javascript,jquery,css,wordpress,Php,Javascript,Jquery,Css,Wordpress,我目前正在开发一个使用WordPress Twenty-Eleven主题的网站,我希望主导航条在滚动过屏幕后能够贴在屏幕顶部,就像本页右侧的段落一样 到目前为止,我已经在标题中添加了代码,以便在开头的head标记之后包含jQuery: <?php wp_enqueue_script("jquery"); ?> <script type="text/javascript" src="<?php bloginfo("template_url"); ?>/js/move

我目前正在开发一个使用WordPress Twenty-Eleven主题的网站,我希望主导航条在滚动过屏幕后能够贴在屏幕顶部,就像本页右侧的段落一样

到目前为止,我已经在标题中添加了代码,以便在开头的head标记之后包含jQuery:

<?php wp_enqueue_script("jquery"); ?>
<script type="text/javascript"
src="<?php bloginfo("template_url"); ?>/js/moveScroller.js"></script>
后来,我在结束头标记之前加入了javascript:

<?php wp_enqueue_script("jquery"); ?>
<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()
    });
});
访问和访问锚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,还可以设置滚动动画,看起来更有趣= 我在一周前使用了这段代码,它不使用“位置固定”,它使用“边距顶部”,但您可以轻松更改它:

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栈交换或WordPress论坛上没有人知道这一点,所以我不得不放弃它:

你也可以考虑在AH上发表文章,谢谢。我不知道: