Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New 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:

    Code:
    <script type="text/javascript">
    $(function(){
        $('.dropdown').hover(function() {
            $(this).addClass('open');
        },
        function() {
            $(this).removeClass('open');
        });
    });
    </script>
    Can anyone advise how we go about disabling this code if on a mobile device i.e bootstraps "xs" size and possibly "sm".

    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

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,303
    Thanks
    30
    Thanked 864 Times in 862 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.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •