以左上角為定點(diǎn),放大縮小,該點(diǎn)位置不變。
方法一:
Html代碼
復(fù)制代碼 代碼如下:
<script type="text/javascript">
//兼容IE和火狐 縮小放大、縮放
function ImageSuofang(args) {
var oImg = document.getElementById("oImg");
if (args) {
oImgoImg.width = oImg.width * 1.1;
oImgoImg.height = oImg.height * 1.1;
}
else {
oImgoImg.width = oImg.width / 1.1;
oImgoImg.height = oImg.height / 1.1;
}
}
</script>
<form>
<div data-orient="center">
<img src="/img/c.jpg" value="放大" />
<input type="button" value="縮小" />
<!-- <input type="button" value="<-Rotate逆時(shí)針"> -->
</form>
復(fù)制代碼 代碼如下:
#biankuang{height:480px;width:320px;margin: 30px auto;}//加一個(gè)border可以看到定點(diǎn)為左上角。
復(fù)制代碼 代碼如下:
var zoomLevel = 0;
var currentWidth = 0;
var currentHeight = 0;
var originalWidth = 0;
var originalHeight = 0;
function initial(){
currentWidth = document.myImage.width;
currentHeight = document.myImage.height;
originalWidth = currentWidth;
originalHeight = currentHeight;
update();
}
function zoomIn(){
document.myImage.width = currentWidth*1.2;
document.myImage.height = currentHeight*1.2;
zoomLevel = zoomLevel + 1;
update();
}
function zoomOut(){
document.myImage.width = currentWidth/1.2;
document.myImage.height = currentHeight/1.2;
zoomLevel = zoomLevel - 1;
update();
}
function resetImage(){
document.myImage.width = originalWidth;
document.myImage.height = originalHeight;
zoomLevel = 0;
update();
}
function update(){
currentWidth = document.myImage.width;
currentHeight = document.myImage.height;
zoomsize.innerText = zoomLevel;
imgsize.innerText = currentWidth + "X" + currentHeight;
}
復(fù)制代碼 代碼如下:
<body>
<div data-orient="center">
<img src="/img/c.jpg" value="放大圖片">
<input type="button" value="縮小圖片">
<input type="button" value="重置圖片">
<span></span> <span></span></p>
</body>
新聞熱點(diǎn)
疑難解答
圖片精選