gpt4 book ai didi

jquery - 在 y 轴旋转时使用 jquery animate 更改圆的颜色

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:40 25 4
gpt4 key购买 nike

我是 j 查询的新手我想在 Y 轴上旋转一个圆 180 度,粉红色背景颜色为 0 到 90 度,红色背景颜色为 90 到 180 度,没有颜色组合。 我插入 j 查询 UI 并编写此代码

html
<body>
<div></div>
</body>

我的 CSS 是:

css
body {
}
div
{
height:100px;
width:100px;
border-radius:100%;
background-color:pink;
transition:all ease-in-out 2s;
}

我的 java 脚本代码是:

$(function () {
$("div").click(function () {

$(this).animate({
backgroundColor: "blue",

}, {
duration: 0,
step: function (now, fx) {


$(this).css('transform', 'rotateY(180deg)');

}

});

});

});

而且我不知道如何定义 0 到 90 度的粉红色背景 和定义 90 到 180 度的红色背景。

如果有人能提供帮助,我将不胜感激

最佳答案

尝试利用 jQuery UI ,将 css transform 值替换为 transform 用于 all ,利用 start .animate() 选项设置 divtransform 属性,设置 backgroundColor >divnowprops 动画对象中大于 89,或等于 90

$(function() {

$("div").click(function() {
var el = this
, n = 180;

$({props: 0})
.animate({
props: n,
}, {
start: function() {
$(el).css("transform", "rotateY(" + n + "deg)")
},
easing: "linear",
step: function(now, fx) {
if (Math.round(now) > 89 || Math.round(now) === 90) {
el.style.backgroundColor = "red";
}
},
duration: 2000
});
});

});
div {
height: 100px;
width: 100px;
border-radius: 100%;
background-color: pink;
transition: transform ease-in-out 2s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<body>
<div></div>
</body>

关于jquery - 在 y 轴旋转时使用 jquery animate 更改圆的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32026469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com