Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 2 of 2
-
04-13-2016, 10:37 AM #1New Coder
- Join Date
- Apr 2011
- Posts
- 55
- Thanks
- 15
- Thanked 0 Times in 0 Posts
only allow script to function depending on screen size, check on resize
Hi all,
I'm currently working on re-designing our sites navigation to work better with mobiles. We are using the bootstrap framework and at present when a user hovers over the menu it shows the dropdown. They can also click the section and it will toggle the dropdown. This is great but on mobiles we want to disable this functionality so that it must be clicked to toggle rather than hover.
The hover code that we use is below:
Can anyone advise how we go about disabling this code if on a mobile device i.e bootstraps "xs" size and possibly "sm".Code:<script type="text/javascript"> $(function(){ $('.dropdown').hover(function() { $(this).addClass('open'); }, function() { $(this).removeClass('open'); }); }); </script>
We would ideally also like it to check whether it should be enabled or disabled if the browser is resized.
Any help would be greatly appreciated.
Tim
-
04-13-2016, 07:19 PM #2Master Coder
- Join Date
- Jan 2011
- Location
- Washington
- Posts
- 6,251
- Thanks
- 30
- Thanked 859 Times in 857 Posts
You ain't gonna like this But .... Stop using JS to do the site navigation. CSS works just fine for this and media queries will adjust them just fine.
As far as I remember Bootstrap has built in stuff to do this. (Don't use it any more).
Here is a page to look at for ideas or for a solution: https://css-tricks.com/responsive-menu-concepts/Last edited by sunfighter; 04-13-2016 at 07:22 PM.
Evolution - The non-random survival of random variants.
Physics is actually atoms trying to understand themselves.



Reply With Quote
