How can I zoom an HTML element in Firefox and Opera?

前端 未结 12 694
猫巷女王i
猫巷女王i 2020-11-29 02:00

How can I zoom an HTML element in Firefox and Opera?

The zoom property is working in IE, Google Chrome and Safari, but it’s not working in Firefox and O

12条回答
  •  天命终不由人
    2020-11-29 02:49

    Use scale instead! After many researches and tests I have made this plugin to achieve it cross browser:

    $.fn.scale = function(x) {
        if(!$(this).filter(':visible').length && x!=1)return $(this);
        if(!$(this).parent().hasClass('scaleContainer')){
            $(this).wrap($('
    ').css('position','relative')); $(this).data({ 'originalWidth':$(this).width(), 'originalHeight':$(this).height()}); } $(this).css({ 'transform': 'scale('+x+')', '-ms-transform': 'scale('+x+')', '-moz-transform': 'scale('+x+')', '-webkit-transform': 'scale('+x+')', 'transform-origin': 'right bottom', '-ms-transform-origin': 'right bottom', '-moz-transform-origin': 'right bottom', '-webkit-transform-origin': 'right bottom', 'position': 'absolute', 'bottom': '0', 'right': '0', }); if(x==1) $(this).unwrap().css('position','static');else $(this).parent() .width($(this).data('originalWidth')*x) .height($(this).data('originalHeight')*x); return $(this); };

    usege:

    $(selector).scale(0.5);
    

    note:

    It will create a wrapper with a class scaleContainer. Take care of that while styling content.

提交回复
热议问题