- Joined
- Feb 27, 2013
- Messages
- 72
- Points
- 0
Ever need a fixed menu when scrolling down on the website. I have a bit of code that can work with you. Just quick thanks to Ruan Vermeulen*for helping me with the JavaScript.
First create a Javascript file and insert this code:
<em>You can give it a name like menu.js</em>
Now enqueue*the Javascript in Wordpress:
You must put this code in the functions file.
<strong>HTML</strong>
Now creat your div in the header.
<strong>CSS</strong>
Now you style it:
That is it. If it is not working ask me on the blog, I will help you. Remember to check if the Javascript is running.
First create a Javascript file and insert this code:
<em>You can give it a name like menu.js</em>
Code:
jQuery(document).ready(function(){
jQuery(window).scroll(function() {
var scrollposition = jQuery(window).scrollTop();
if((scrollposition <= 250)) {
jQuery(".small-menu").hide();
} else if ((scrollposition > 250)) {
jQuery(".small-menu").show();
}
});
});
You must put this code in the functions file.
Code:
function my_scripts() {
wp_enqueue_script(
'custom-script',
get_bloginfo( 'template_url' ) . '/js/menu.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
Now creat your div in the header.
Code:
<div class="small-menu">
*<ul>
* * * <li><a href="link">Link name</a></li>
*</ul>
*<div id="scrollmenu" class="sidebar"> ////i created a widget area. If you don't know how it works you may ask me or browse the blog
* * * <?php dynamic_sidebar( 'scrollnav' ); ?>
*</div>
*</div>
Now you style it:
Code:
.small-menu {
background-color: #F88123;
width:960px;
height:33px;
display: none;
position:fixed;
z-index: 9999;
}