1

I've created two buttons in my html code

<a href="#" class="increase">+</a>
<a href="#" class="decrease">-</a>

what i want to do is to click in the buttons and scale the page

i developed a jquery script, but it only works on chrome

  $(".decrease").click(function () {
        $("body").css('zoom',function (index,value) {
            if(value < 0.8){
                return value;
            } else {
                return parseFloat(value) - 0.1;
            }
        });
  });

  $(".increase").click(function () {
        $("body").css('zoom',function (index,value) {
            if(value > 1.2){
                return value;
            } else {
                return parseFloat(value) - 0.1;
            }
        });
  });

can anyone help me?

thanks

3 Answers3

1

See here jsfiddle - http://jsfiddle.net/1totyrhj/

This variant will work in all modern browsers.

JavaScript

(function () {
    var currentScale = 1,
        cssPrefixesMap = [
            'scale',
            '-webkit-transform',
            '-moz-transform',
            '-ms-transform',
            '-o-transform',
            'transform'
        ];

    function setScale(scale) {
        var scaleCss = {};

        cssPrefixesMap.forEach(function (prefix) {
            scaleCss[prefix] = 'scale(' + scale + ')';
        });

        $('div').css(scaleCss);
    }

    $(".decrease").click(function () {
        setScale(currentScale = currentScale - 0.1);
    });

    $(".increase").click(function () {
        setScale(currentScale = currentScale + 0.1);
    });
})();
Eugene Obrezkov
  • 2,910
  • 2
  • 17
  • 34
0

There's a load of ways browsers handle CSS zooming, for example when doing a x2 zoom:

zoom: 2; /* IE */
-moz-transform: scale(2); /* Firefox */
-moz-transform-origin: 0 0;
-o-transform: scale(2); /* Opera */
-o-transform-origin: 0 0;
-webkit-transform: scale(2); /* Safari And Chrome */
-webkit-transform-origin: 0 0;
transform: scale(2); /* Standard Property */
transform-origin: 0 0;  /* Standard Property */

You'll need a way to handle them all. (Property list shamelessly stolen from this thread: complete styles for cross browser CSS zoom)

Community
  • 1
  • 1
Danny Hoek
  • 420
  • 4
  • 14
0

Change your class for an ID, and then try this out :

    var currFFZoom = 1;
    var currIEZoom = 100;

    $('#increase').on('click',function(){
        if ($.browser.mozilla){
            if(currFFZoom < 1.2)
            {
            var step = 0.2;
            currFFZoom += step; 
            $('body').css('MozTransform','scale(' + currFFZoom + ')');
            }
        } else {
            if(currIEZoom < 120)
            {
            var step = 20;
            currIEZoom += step;
            $('body').css('zoom', ' ' + currIEZoom + '%');
        }}
    });

    $('#decrease').on('click',function(){
        if ($.browser.mozilla){
             if(currFFZoom > 0.8)
            {
            var step = 0.2;
            currFFZoom -= step;                 
            $('body').css('MozTransform','scale(' + currFFZoom + ')'); }

        } else {
            if(currIEZoom > 80)
            {
            var step = 20;
            currIEZoom -= step;
            $('body').css('zoom', ' ' + currIEZoom + '%');
            }
        }
    });

EDIT : Adapted to block after a certain amount of scale (Min/max).

ChoiBedal
  • 111
  • 7