Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在div内旋转时如何保持随机输入图像居中_Javascript_Html_Css_Rotation - Fatal编程技术网

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

Javascript 在div内旋转时如何保持随机输入图像居中,javascript,html,css,rotation,Javascript,Html,Css,Rotation,我试图在显示图像时旋转图像,当我旋转到90度和270度时,我很难将图像保持在范围内的中心位置。这是我的密码 .cn { background: url('images/transparent.png') repeat; height: 200px; position: relative; vertical-align: middle; } .east_largerwidth { position: absolute; -webkit-transform-origin: 75px 125px

我试图在显示图像时旋转图像,当我旋转到90度和270度时,我很难将图像保持在
范围内的中心位置。这是我的密码

.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 */
} 
下面是旋转显示图像的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";
                 }
}
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();" />

旋转90度和270度

有没有人能帮助我在旋转到90度和270度时如何使图像保持水平? 谢谢。

中心块{
显示:块;
左边距:自动;
右边距:自动;
}