87,993
社区成员
发帖
与我相关
我的任务
分享
<div class="rotate" id="rotate" style="background:#000; width:300px; height:200px;"></div>
<script type="text/javascript">
window.onload = function(){
var div = document.getElementById("rotate");
var myImage = document.createElement("img");
var width = div.offsetWidth, height = div.offsetHeight;
myImage.src = "https://www.baidu.com/img/bd_logo1.png";
myImage.style.width = height + 'px';
myImage.style.height = width + 'px';
myImage.style.marginLeft = (width - height) / 2 + 'px';
myImage.style.marginTop = (height - width) / 2 + 'px';
myImage.style.transform = 'rotate(90deg)';
div.appendChild(myImage);
};
</script>