根據W3C定義 ,scale主要是進行縮放和轉化:javascript
<div class="wrap"> <div class="UI-scale1"></div> <div class="UI-scale2"></div> <div class="UI-scale3"></div> </div>
CSS代碼css
.wrap{ position: relative; } .UI_scale1{ position: relative; width: 200px; height: 50px; border-bottom:1px solid #000; } .UI_scale2{ position:relative; top: 0px; left: 0px; width: 200px; height: 50px; border-bottom: 1px solid #000; } @media screen and (-webkit-min-device-pixel-ratio:2){ .UI_scale2{ transform: scale(1,0.5); transform-origin:left center; } }
function scale(){ var origin_H = 667, origin_W = 375, win_H = $(window).height(), win_W = $(window).width(); var ratio1 = win_H / origin_H , ratio2 = win_W / origin_W ; if(ratio1<ratio2){ $('.page1-wrap').css({ '-webkit-transform':'scale('+ratio1+')' }) } else{ $('.page1-wrap').css({ '-webkit-transform':'scale('+ratio2+')' }) } }
@-webkit-keyframes pulse { 0% { -webkit-transform: scale3d(1,1,1); transform: scale3d(1,1,1) } 50% { -webkit-transform: scale3d(1.05,1.05,1.05); transform: scale3d(1.05,1.05,1.05) } 100% { -webkit-transform: scale3d(1,1,1); transform: scale3d(1,1,1) } }
HTML代碼html
<div class="wrap"> <div class="UI-scale1"></div> <div class="UI-scale2"></div> <div class="UI-scale3"></div> </div>
CSS代碼java
.wrap{ position: relative; background-color: #ccc; } .UI_scale1{ position: relative; top: 0px; width: 100px; height: 50px; font-size:14px; line-height: 24px; margin-left: 50px; padding: 50px; border-bottom:1px solid #000; background-color: red; } .UI_scale2{ position: relative; top: 0px; width: 100px; height: 50px; font-size:14px; line-height: 24px; margin-left: 50px; padding: 50px; border-bottom:1px solid #000; transform: scale(0.5); background: blue; transform-origin: center center; }
如圖所示能夠直接影響到全部帶px的屬性,可是因爲scale屬性不會引發重排,會致使父元素的高度和寬度都不會受到影響.web
1.scale會只會引發了當前元素
佈局
2.zoom會引發重排,因此會影響所有元素
性能