gpt4 book ai didi

javascript - 如何使用 javascript 或 jquery 旋转 li?

转载 作者:行者123 更新时间:2023-11-28 01:15:37 25 4
gpt4 key购买 nike

抱歉出现语法错误。我无法正确提出问题,所以这就是为什么我使用图像来理解我的问题。我有三个 LI 圆圈,我想创建一个能够

的函数
  • Onclick li 将旋转并停止在橙色框上并更改其他两个位置。
  • 其他两个li也将类似地工作

注意:

Li 基本上是在 onclick 时显示其 div。请帮助我

Image

这是我的 code

CSS

ul{
width:100px;
height:100px;
border-radius:100%;
border:2px solid #000000;
text-align:center;
padding:5%
}
ul li{
list-style:none;
cursor:pointer;
margin-bottom:10px;
width:30%;
height:30%;
padding:5%;
border:1px solid #000;
text-align:center;
}
ul li div{
display:none;
}
.skill-box{
width:500px;
height:70px;
border:2px solid #000;
left:20%;
position:absolute;}

HTML

<ul id="circle">
<li>
<div class="pie"></div>
one <div class="skill-box">Skill Box 1</div>
</li>
<li>
two <div class="skill-box">Skill Box 2</div>
</li>
<li>
Three <div class="skill-box">Skill Box 3</div>
</li>
</ul>

这是用于显示 li 框的 JavaScript

<script>  
$("li").click(function(){
$("li div").not($("div",$(this))).hide();
$("div",$(this)).fadeToggle("fast");
})

</script>

最佳答案

基本上,您想要构建的是一个轮盘赌轮。

一些简单的谷歌搜索找到了我这个网站:

http://tech.pro/tutorial/1008/creating-a-roulette-wheel-using-html5-canvas

您需要一个 htlm5 Canvas 元素。如果您需要支持某些旧版本的 IE,这将不起作用。这里有很多热链接代码,所以我会推荐您访问该网站。如果它变得不可用。我确定googling for Javascript roulette wheel会带你去某个地方。

编辑:HTML 代码:

<input type="button" value="spin" style="float:left;" />
<canvas id="canvas" width="500" height="500"></canvas>

生成轮子的javascript:

var colors = ["#B8D430", "#3AB745", "#029990", "#3501CB",
"#2E2C75", "#673A7E", "#CC0071", "#F80120",
"#F35B20", "#FB9A00", "#FFCC00", "#FEF200"];
var restaraunts = ["Wendy's", "McDonalds", "Chick-fil-a", "Five Guys",
"Gold Star", "La Mexicana", "Chipotle", "Tazza Mia",
"Panera", "Just Crepes", "Arby's", "Indian"];

var startAngle = 0;
var arc = Math.PI / 6;
var spinTimeout = null;

var spinArcStart = 10;
var spinTime = 0;
var spinTimeTotal = 0;

var ctx;

function drawRouletteWheel() {
var canvas = document.getElementById("canvas");
if (canvas.getContext) {
var outsideRadius = 200;
var textRadius = 160;
var insideRadius = 125;

ctx = canvas.getContext("2d");
ctx.clearRect(0,0,500,500);


ctx.strokeStyle = "black";
ctx.lineWidth = 2;

ctx.font = 'bold 12px Helvetica, Arial';

for(var i = 0; i < 12; i++) {
var angle = startAngle + i * arc;
ctx.fillStyle = colors[i];

ctx.beginPath();
ctx.arc(250, 250, outsideRadius, angle, angle + arc, false);
ctx.arc(250, 250, insideRadius, angle + arc, angle, true);
ctx.stroke();
ctx.fill();

ctx.save();
ctx.shadowOffsetX = -1;
ctx.shadowOffsetY = -1;
ctx.shadowBlur = 0;
ctx.shadowColor = "rgb(220,220,220)";
ctx.fillStyle = "black";
ctx.translate(250 + Math.cos(angle + arc / 2) * textRadius,
250 + Math.sin(angle + arc / 2) * textRadius);
ctx.rotate(angle + arc / 2 + Math.PI / 2);
var text = restaraunts[i];
ctx.fillText(text, -ctx.measureText(text).width / 2, 0);
ctx.restore();
}

//Arrow
ctx.fillStyle = "black";
ctx.beginPath();
ctx.moveTo(250 - 4, 250 - (outsideRadius + 5));
ctx.lineTo(250 + 4, 250 - (outsideRadius + 5));
ctx.lineTo(250 + 4, 250 - (outsideRadius - 5));
ctx.lineTo(250 + 9, 250 - (outsideRadius - 5));
ctx.lineTo(250 + 0, 250 - (outsideRadius - 13));
ctx.lineTo(250 - 9, 250 - (outsideRadius - 5));
ctx.lineTo(250 - 4, 250 - (outsideRadius - 5));
ctx.lineTo(250 - 4, 250 - (outsideRadius + 5));
ctx.fill();
}
}

function spin() {
spinAngleStart = Math.random() * 10 + 10;
spinTime = 0;
spinTimeTotal = Math.random() * 3 + 4 * 1000;
rotateWheel();
}

function rotateWheel() {
spinTime += 30;
if(spinTime >= spinTimeTotal) {
stopRotateWheel();
return;
}
var spinAngle = spinAngleStart - easeOut(spinTime, 0, spinAngleStart, spinTimeTotal);
startAngle += (spinAngle * Math.PI / 180);
drawRouletteWheel();
spinTimeout = setTimeout('rotateWheel()', 30);
}

function stopRotateWheel() {
clearTimeout(spinTimeout);
var degrees = startAngle * 180 / Math.PI + 90;
var arcd = arc * 180 / Math.PI;
var index = Math.floor((360 - degrees % 360) / arcd);
ctx.save();
ctx.font = 'bold 30px Helvetica, Arial';
var text = restaraunts[index]
ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10);
ctx.restore();
}

function easeOut(t, b, c, d) {
var ts = (t/=d)*t;
var tc = ts*t;
return b+c*(tc + -3*ts + 3*t);
}

drawRouletteWheel();

关于javascript - 如何使用 javascript 或 jquery 旋转 li?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23872019/

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