I have a snag in a static website to wordpress theme translation. The original navbar in the website has a host of jquery’s and custom javascript for navigation. It makes really pretty animated transitions for hover and mouse over events (and the client does not want to change it).
I would like to swap the the navigation bar for smaller screen sizes. So I add some css to the media query rules that I set up but the custom.js file still wants to play with my new nav bar because of the div id and or class, which is made in the php header for the wordpress files.
So the basic question is how do I swap the the div id or class based on the size of the browser? My original div is:
<div id="main_navigation" class="main-menu" role="navigation">
<?php html5blank_nav(); ?>
</div><!-- NAVIGATION CLOSE -->
Many thanks for any advice?
Maybe this solution looks weird, but if you can’t disable the custom.js file for smaller screen sizes, then you have to be sure that any script that makes changes to the html of navigation is executed before the custom.js file. And it will not guarantee that everything will work without problems.
This solution uses html templates to create the navigation on server side. Template is stored as
'text/template'
script in footer.Put this above
wp_footer();
call infooter.php
file.Replace original nav (
<div id="main_navigation" ... </div>
) with placeholder:And, finally, put this script below placeholder ( or enqueue with
wp_enqueue_script()
if you like ):It is fairly flexible and easy solution, because now you have full control over html. You can, for example, create two completely different templates for different screens, or just modify the wrapper of the navigation.
You can get window height and with via jQuery
.height()
and.width()
methods. Then you’ll need to use.attr('class')
to fetch the class and do any kind of modification. Something like this:Don’t forget to wrap this function into a
$(document).ready
or something similar in order to assure it will be properly loaded.Maybe you can use something like this with jquery
Change 440 for any value you want to be the screen width.
You are going to firs remove the class the nav already have .main-menu and then you are going to add your own class to control the nav .name_of_class
In the else statement, you are just going back to the default class it was.
You can also take a look in here: http://api.jquery.com/addclass/
Hope it helps.