简体   繁体   English

在div中旋转时如何保持居中的随机输入图像

[英]How to keep centering random input image when rotated within div

I'm trying to rotate an image while it is being displayed, I'm having trouble keeping it in the center within a < div > when I rotated to 90 and 270 degree. 我正在尝试旋转显示时的图像,但是当我将其旋转到90度和270度时,无法将其保持在<div>的中心。 Here's my code 这是我的代码

.cn {
background: url('images/transparent.png') repeat; 
height: 200px;
position: relative;
vertical-align: middle; 
}

.east_largerwidth {
position: absolute;
-webkit-transform-origin: 75px 125px;
-moz-transform-origin: 75px 125px;
-ms-transform-origin: 75px 125px;
-o-transform-origin: 75px 125px;
transform-origin: 75px 125px;
transform:rotate(270deg);
-ms-transform:rotate(270deg); /* IE 9 */
-webkit-transform:rotate(270deg); /* Safari and Chrome */
}  

.west_largerwidth {
display:block;
margin:auto;
-webkit-transform-origin: 75px 75px;
-moz-transform-origin: 75px 75px;
-ms-transform-origin: 75px 75px;
-o-transform-origin: 75px 75px;
transform-origin: 75px 75px;
transform:rotate(90deg);
-ms-transform:rotate(90deg); /* IE 9 */
-webkit-transform:rotate(90deg); /* Safari and Chrome */
} 

here's the javascript function that rotates the display image 这是旋转显示图像的javascript函数

function rotatefunction() {

    if (document.getElementById("ContentPlaceHolder1_Image1").classList.contains('east_largerwidth')) {

                 img.setAttribute('class', 'north');
                     if (hidderValue > 200) {
                         document.getElementById("ContentPlaceHolder1_Image1").style.width = "auto";
                         document.getElementById("ContentPlaceHolder1_Image1").style.height = "200px";
                     }
} else if ( document.getElementById("ContentPlaceHolder1_Image1").classList.contains('west_largerwidth')) {
             img.setAttribute('class', 'south');
                 if (hidderValue > 200) {
                     document.getElementById("ContentPlaceHolder1_Image1").style.width = "auto";
                     document.getElementById("ContentPlaceHolder1_Image1").style.height = "200px";
                 }
}

the html HTML

<div id="divBackground" class="cn" >
  <asp:Image ID="Image1" runat="server" ImageUrl="" style="height: 200px; max-  height: 200px; max-width: 100%;" class='north'/>
</div>
<div class="fileUpload btn btn-warning">
  <input id="inputFile" runat="server" type="file" name="file" onchange="previewFile()" CssClass="upload" />
</div>
<asp:Button UseSubmitBehavior="false" ID="btnRotate" runat="server" Text="Rotate" class="btn btn-warning" OnClientClick="return rotatefunction();" />

0 and 180 degree rotated 0和180度旋转 0度旋转 180度

90 and 270 degree rotated 分别旋转90和270度 90度 270度

Can anyone please help me on how I will keep the image on the center horizontally when rotated to 90 and 270 degree? 有人可以帮我旋转90度和270度后如何将图像水平居中吗? Thank you. 谢谢。

 center-block { display: block; margin-left: auto; margin-right: auto; } 

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

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