jquery实现每点击一次旋转90度

$(document).ready(function(){$("input").click(function(){$("#parent").animate({-webki... $(document).ready(function(){
$("input").click(function(){
$("#parent").animate({
-webkit-transform:"rotateY(+=90deg)" //就是这行代码,应该怎么写?
});
});
});
展开
 我来答
老何先生
推荐于2016-03-09
知道答主
回答量:23
采纳率:0%
帮助的人:9.6万
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS 旋转函数,兼容各个浏览器</title>
<script id="jscode">
function hy_rotate(obj, rotate){
if(obj){
function rotate_set_style(obj, key, value){
obj.style[key] = value;
}

function rotate_float(n, b){
b = isNaN(parseInt(b)) ? -1 : parseInt(b);
return isNaN(parseFloat(n)) ? 0 : (b == 0) ? parseInt(parseFloat(n)) : (b > 0) ? parseFloat(parseFloat(n).toString().replace((new RegExp('^(\\d+)\\.(\\d{'+b+'})\\d*$')), '$1.$2')) : parseFloat(n);
}

rotate = rotate % 360;
if(rotate < 0){
rotate = 360 + rotate
}
rotate = rotate_float(rotate, 2);

var rpi = rotate * Math.PI / 180, c = Math.cos(rpi), s = Math.sin(rpi), oh = obj.offsetHeight, ow = obj.offsetWidth, pw = rotate_float((oh * Math.abs(s) + ow * Math.abs(c)), 2), ph = rotate_float((oh * Math.abs(c) + ow * Math.abs(s)), 2), tw = (rotate % 180 == 0) ? 0 : ((pw - ow) / 2), th = (rotate % 180 == 0) ? 0 : ((ph - oh) / 2), css3 = 'translate(' + tw + 'px, ' + th + 'px) rotate(' + rotate + 'deg)', css3key = '', dbstyle = document.body.style, css3keys = ['transform', '-moz-transform', '-webkit-transform', '-o-transform', '-ms-transform'];

for(var i in css3keys){
if(css3keys[i] in dbstyle){
css3key = css3keys[i];
}
}

if(css3key == ''){
rotate_set_style(obj, 'filter', 'progid:DXImageTransform.Microsoft.Matrix(M11=' + c + ', M12=' + (-s) + ', M21=' + s + ', M22=' + c + ', sizingMethod=\'auto expand\')');
}else{
obj.parentNode.style.width = pw + 'px';
obj.parentNode.style.height = ph + 'px';
rotate_set_style(obj, css3key, css3);
}
}
}
</script>
<style>
.list{clear:both; padding:20px;}
.block{background:#FF99FF; padding:5px; float:left;}
.rotate{background:#FF0000; width:200px; padding:5px;}
.txt{background:#3366FF; padding:10px; color:#FFFFFF; font-size:12px; margin-bottom:10px;}
.code{border:#3333FF dotted 1px; padding:10px; background:#FFCCFF; clear:both;}
</style>
</head>
<body>
<div>JS 旋转函数,兼容各个浏览器</div>
<div class="list">
<div class="block">
<div>
<div class="rotate" id="rotate">
<div class="txt">
我的角度是 <span id="rotate_num"></span>°
</div>
<img src="http://www.fjsen.com/images/attachement/jpg/site2/20130513/001b77b4c2f212fa86172f.jpg" />
</div>
</div>
</div>
</div>
<script>
function $id(id){
return document.getElementById(id);
}
var rrr = 0;
var sss = 0;
var iii = 0;
var aaa = $id('rotate');
var bbb = $id('rotate_num');
function zzz(){
rrr = rrr+1;
bbb.innerHTML = rrr;
hy_rotate(aaa, rrr);
}
aaa.onclick = function(){
if(sss == 0){
iii = setInterval(zzz, 20);;
sss = 1;
}else{
clearInterval(iii);
sss = 0;
}
}

</script>
</body>
</html>
yugi111
2015-02-05 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.3亿
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>YuGiOh</title>
<style type="text/css">
#div {
position: absolute;
top: 50px;
left: 300px;
width: 300px;
height: 300px;
line-height: 300px;
text-align: center;
border: 1px solid black;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
var rotateHTML5 = function (limit)
    {
    var reg = /(rotate\([\-\+]?((\d+)(deg))\))/i;
    var wt = div.style['-webkit-transform'], wts = wt.match (reg);
    var $2 = RegExp.$2;
    console.log ($2);
    div.style['-webkit-transform'] = wt.replace ($2, parseFloat (RegExp.$3) + limit + RegExp.$4);
    }
    
    var rotateIE = function (obj)
    {
    var d = !!obj.d ? obj.d : 1;
    var r = d * Math.PI / 180;
    costheta = Math.cos (r);
    sintheta = Math.sin (r);
    obj.style.filter = "progid:DXImageTransform.Microsoft.Matrix()";
    var item = obj.filters.item (0);
    var width = obj.clientWidth;
    var height = obj.clientHeight;
    item.DX = -width / 2 * costheta + height / 2 * sintheta + width / 2;
    item.DY = -width / 2 * sintheta - height / 2 * costheta + height / 2;
    item.M11 = costheta;
    item.M12 = -sintheta;
    item.M21 = sintheta;
    item.M22 = costheta;
    obj.timer = setTimeout (function ()
    {
    var dx = d + 1;
    dx = dx > 360 ? 1 : dx;
    obj.d = dx;
    rotate (obj, dx);
    }, 30);
    };
    
    var start = function ()
    {
    if (!!div.interval)
    {
    clearInterval (div.interval);
    delete div.interval;
    }
    else
    {
    div.interval = setInterval (function ()
    {
    /.*webkit.*/i.test (navigator.userAgent) ? rotateHTML5 (1) : rotateIE (div);
    }, 30);
    }
    }
</script>
</head>
<body>
<button onclick="start();">rotate</button>
<div id="div" style="border-radius: 90px; -webkit-transform: rotate(10deg);">ROTATE</div>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
luocongjay
2013-06-27 · TA获得超过949个赞
知道小有建树答主
回答量:1382
采纳率:33%
帮助的人:428万
展开全部
直接改css 不需要animate
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式