简体   繁体   English

如何按父div缩放内部内容?

[英]How to zoom inner contents as per the parent div?

在此处输入图片说明

Picture clearly describes that the inner contents is larger than than the parent container, so I want to use zoom technique so that the inner contents proportionally decrease to fit the parent container. 图片清楚地描述了内部内容大于父容器,因此我想使用缩放技术,以便内部内容按比例减小以适合父容器。

So, how could I implement? 那么,我该如何实施?


I'm just talking about using zoom technique like this: 我只是在谈论使用这样的缩放技术:

.inner-container{
zoom: .5;
-moz-transform: scale(.5);
}

But I'm stuck how can I calculate using jquery or javascript the zoom value should be set! 但是我卡住了如何使用jquery或javascript计算应该设置zoom值!

I guess what you would like to do is something like this: 我想您想做的是这样的:

DEMO: http://jsfiddle.net/naokiota/8JAUA/17/ 演示: http : //jsfiddle.net/naokiota/8JAUA/17/

HTML: HTML:

<div class="parent">
    <div class="inner-content">
      .....
    </div>
</div>

JavaScript: JavaScript:

$(".parent").each(function(){

    // get parent height you intend to show
    var p   = $(this).css("padding").replace("px","");
    var h   = $(this).css("height").replace("px","");
    var ph  = h-2*p; 

    // get inner height
    var $ic = $(this).find(".inner-content");
    var ih  = $ic.height();

    // set zoom size
    $ic.css('zoom',ph/ih);

    $(this).height(ph);

});

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM