gpt4 book ai didi

jquery - 围绕居中图像 float 图像

转载 作者:太空宇宙 更新时间:2023-11-04 07:06:01 25 4
gpt4 key购买 nike

我搜索了 javascript 动画库以及 images floating with strings attached to the center image 的这种配置的 css 示例。 .首先我尝试了 using this code from this example ,但我找不到一种动画旋转功能的方法,因此图像(在这个例子中被视为按钮)会漂浮在居中按钮周围并附加一个字符串。我希望我能表达自己,我也恢复了这个问题的最后一部分。

这是该示例的 jquery 代码:

var angleStart = -360;

// jquery rotate animation
function rotate(li,d) {
$({d:angleStart}).animate({d:d}, {
step: function(now) {
$(li)
.css({ transform: 'rotate('+now+'deg)' })
.find('label')
.css({ transform: 'rotate('+(-now)+'deg)' });
}, duration: 0
});
}

// show / hide the options
function toggleOptions(s) {
$(s).toggleClass('open');
var li = $(s).find('li');
var deg = $(s).hasClass('half') ? 180/(li.length-1) : 360/li.length;
for(var i=0; i<li.length; i++) {
var d = $(s).hasClass('half') ? (i*deg)-90 : i*deg;
$(s).hasClass('open') ? rotate(li[i],d) : rotate(li[i],angleStart);
}
}

$('.selector button').click(function(e) {
toggleOptions($(this).parent());
});

setTimeout(function() { toggleOptions('.selector'); }, 100);

此函数使圆圈从中心和围绕中心圆旋转。

所以继续这个堆栈问题:

  1. 我需要 float (这意味着它们将在 x 和 y 上移动但有限制,因此它们不会与其他图像重叠)img 围绕居中的 img 同时附加到字符串 like represented in this img .

  2. 我需要在用户滚动时显示它们,我尝试使用 on( 'scroll', ... ) 但是这个例子使用了这个 toggleOptions 并且它传递了这个我不明白是什么的“s”参数确实如此。

  3. 如果你能告诉我一种在 float img 和中心 img 之间画一条线的方法,那就太好了。

最佳答案

我实际上能够用 p5.js 做到这一点。 Here is the CodePen .如果有人想克隆它,我会把它放在我的 github 上并在此处链接它。

编辑: Github Link

这是javascript代码:

var canvas;
var width = window.innerWidth;
var height = window.innerHeight;
let angle = 0;
var unitSize = [125,125,125,125,125,125,125,125,125];
var xoff = [0,1,2,3,4,5,6,7,8];
var x = [0,1,2,3,4,5,6,7,8];
var circles = [0,1,2,3,4,5,6,7,8];
var images = [0,1,2,3,4,5,6,7,8];

// function preload(){
// images[0] = loadImage('images/img0.jpg');
// images[1] = loadImage('images/img1.jpg');
// images[2] = loadImage('images/img2.jpg');
// images[3] = loadImage('images/img3.jpg');
// images[4] = loadImage('images/img4.jpg');
// images[5] = loadImage('images/img5.jpg');
// images[6] = loadImage('images/img6.jpg');
// images[7] = loadImage('images/img7.jpg');
// images[8] = loadImage('images/img8.jpg');
// images[9] = loadImage('images/img9.jpg');
// }

function setup() {
canvas = createCanvas(window.innerWidth, window.innerHeight);
//use WEBGL when using texture()
canvas.parent("canvas");
}

function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}

//if you don't want to spin it when scroll delete this
function mouseWheel(event) {
angle += (event.delta)*0.001;
}


function draw() {
//delete this line when using WEBGL
translate(width/2,height/2);
noStroke();
background( 255 );
fill(126);
ellipse(0, 0, 260, 260);
//texture(images[9]);
//rotate the black ellipses
rotate(angle);
//rotation speed
angle = angle + 0.0007;
//using noise() to get smooth random x values and using xoff to get different random values for each black ellipse
for (var i = x.length - 1; i >= 0; i--) {
x[i] = map(noise(xoff[i]), 0 , 1 , 200 , 230);
xoff[i] += 0.01;
}
//draw the black ellipses
for( var i = 0; i < circles.length; i++) {
rotate( TWO_PI/9.0 );
//texture(images[i]);
stroke(0);
line( 0, 0,x[i],0);
fill(0);
//draw each ellipse with different x value
ellipse( x[i], 0, unitSize[i], unitSize[i] );
}
}

这是 HTML 代码:

(但不要忘记导入脚本)

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
<div id="canvas" style="height: 100%;width: 100%"></div>
</body>
</html>

关于jquery - 围绕居中图像 float 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51619670/

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