多种方式,实现点击按钮图片旋转
点击按钮实现向左或者向右旋转90度,点击四次也就是直至旋转到360度,恢复原状,
方法一、js实现
<!DOCTYPE html>
<html>
<head>
<title>图片旋转</title>
<script>
window.onload = function(){
var current = 0;
document.getElementById('rotate').onclick = function(){
current = (current+90)%360;
this.style.transform = 'rotate('+current+'deg)';
}
};
</script>
</head>
<body>
<img id ="rotate" src="">
</body>
</html>
方法二、jQuery实现
<button class="btn btn-default" style="float: right;" type="button" id="rotate_image">旋转图片</button>
<img src="xx" id="img1">
var r = 0
$("#rotate_image").on('click', function () {
img_lists = [];
img_lists.push($("#img1").attr('src'))
r += 90
$("#img1").css('transform', 'rotate('+r+'deg)');
})