Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-15-2013, 09:17 PM   PM User | #1
eydg
New Coder

 
Join Date: Sep 2012
Posts: 71
Thanks: 2
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
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?
eydg is offline   Reply With Quote
Old 01-15-2013, 10:18 PM   PM User | #2
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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();
  });
};
tempz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:42 PM.


Advertisement
Log in to turn off these ads.