Javascript 旋转jqueryUI模式的问题
我正试图使用jQueryUI中的Javascript 旋转jqueryUI模式的问题,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我正试图使用jQueryUI中的.switchClass函数,基于导航栏$('.selectcircle')中单击的元素,构建一个旋转到特定元素的模式 但是,我对实际涉及的数学有问题,通常会导致: 一次只能旋转一个或两个图元 多个元素可以获得类,但不会失去类 偶尔会丢失所有涉及的类,将相关元素默认为CSS中的标准大小和位置 代码 编辑:此问题现已修复 var-selectcircle=$('.selectcircle'); var linkmoddet=$('.linkmoddet');
.switchClass
函数,基于导航栏$('.selectcircle')
中单击的元素,构建一个旋转到特定元素的模式
但是,我对实际涉及的数学有问题,通常会导致:
- 一次只能旋转一个或两个图元
- 多个元素可以获得类,但不会失去类
- 偶尔会丢失所有涉及的类,将相关元素默认为CSS中的标准大小和位置
var-selectcircle=$('.selectcircle');
var linkmoddet=$('.linkmoddet');
选择圆圈。单击(函数(){
var circleindex=$(this).index()-1;
var中心指数;
控制台日志(circleindex);
选择Circle.each(功能(索引){
if(circleindex==索引)
{
log($(this));
}
});
linkmoddet.each(函数(索引){
if($(this).hasClass('moddetcenter'))
{
centerindex=$(this.index();
log(“中心为索引#”+centerindex);
}
变量旋转=中心指数-圆形指数;
//这就是我开始有问题的地方。
var i=$(this).index()+旋转;
var j;
如果(i=moddetids.length)
{
j=i-moddetids.length;
$(this).switchClass(类[i-$(this).index()],类[j]);
}
其他的
{
如果(旋转<0)
{
j=i-1;
}
其他的
{
j=i+1;
}
$(此).switchClass(类[i],类[j]);
}
});
});
有没有人对如何以比上述更简单的方式实现预期的结果有想法?好吧,我通过以下步骤找到了答案:
linkmoddet.each(function (index){
var classnum;
var newrot;
if ($(this).hasClass('moddetcenter'))
{
classnum = 2;
if (rotation < 0)
{
rotation += classes.length;
}
if (classnum + rotation >= classes.length)
{
newrot = classnum + rotation - classes.length;
$(this).switchClass(classes[classnum],classes[newrot]);
}
else if (rotation != 0)
{
$(this).switchClass(classes[classnum],classes[classnum+rotation]);
}
}
/* This is repeated for all the classes available in the classes array.
* ie: 0 being the first class, 1 being the second, etc. It's not an
* elegant solution, but it works for my current needs at the moment
* while I put it in a function in the future. */
linkmoddet.each(函数(索引){
变量classnum;
新腐变种;
if($(this).hasClass('moddetcenter'))
{
classnum=2;
如果(旋转<0)
{
旋转+=类。长度;
}
if(classnum+旋转>=classes.length)
{
newrot=classnum+rotation-classes.length;
$(this.switchClass(类[classnum],类[newrot]);
}
否则如果(旋转!=0)
{
$(this.switchClass(类[classnum],类[classnum+旋转]);
}
}
/*对于类数组中可用的所有类都重复此操作。
*ie:0是第一个类,1是第二个类,等等。它不是一个
*优雅的解决方案,但它适合我目前的需要
*而我把它放在未来的函数中*/
谢谢
linkmoddet.each(function (index){
var classnum;
var newrot;
if ($(this).hasClass('moddetcenter'))
{
classnum = 2;
if (rotation < 0)
{
rotation += classes.length;
}
if (classnum + rotation >= classes.length)
{
newrot = classnum + rotation - classes.length;
$(this).switchClass(classes[classnum],classes[newrot]);
}
else if (rotation != 0)
{
$(this).switchClass(classes[classnum],classes[classnum+rotation]);
}
}
/* This is repeated for all the classes available in the classes array.
* ie: 0 being the first class, 1 being the second, etc. It's not an
* elegant solution, but it works for my current needs at the moment
* while I put it in a function in the future. */