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
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post

    code equivalent of ctrl+ and ctrl-

    each major browser nicely zooms in and out html these days.

    Is there a smart way to achieve this with a line of code?

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Code:
    jQuery.fn.zoom = function(fn) {
      jQuery(document).keydown(function(e){
        switch (true) {
          case jQuery.browser.mozilla || jQuery.browser.msie :
            if (e.ctrlKey && (
              e.which == 187 ||
              e.which == 189 ||
              e.which == 107 ||
              e.which == 109 ||
              e.which == 96  ||
              e.which == 48
            )) fn();
            break;
          case jQuery.browser.opera :
            if (
              e.which == 43 ||
              e.which == 45 ||
              e.which == 42 ||
              (e.ctrlKey && e.which == 48)
            ) fn();
            break;
          case jQuery.browser.safari :
            if (e.metaKey && (
              e.charCode == 43 ||
              e.charCode == 45
            )) fn();
            break;
        }
        return;
      });
    
      jQuery(document).bind('mousewheel', function(e){
        if (e.ctrlKey) fn();
      });
    
      jQuery(document).bind('DOMMouseScroll', function(e){
        if (e.ctrlKey) fn();
      });
    };


  •  

    Posting Permissions

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