-4

我有这些变量:

var menuItem_place = 0;
var menuItem_position = 0;
var menuItem_limit = parseInt($('.slideshowImage').length) - 1;

它们是我拥有的幻灯片的关键变量。我需要将 css 属性和一些动画元素与变量关联起来menuItem_place

例如:

if(slideshowItem_place = 0){
  $(this).({'background-color':'black'}, 150);
}

我已经尝试了一堆 if/else 但它不起作用。完整的上下文-FIDDLE

4

1 回答 1

0

不幸的是,不可能将回调附加到变量。回调仅适用于以不可预测的方式发生的事情——通常是用户输入。使用变量,您始终可以跟踪代码使用它的那些地方。

您真正要寻找的是更改这些变量的常见位置 - 实际上是菜单项动画的位置。如果您查看click事件的每个回调,您会注意到它们menu_animateClick();最后都会调用 - 这可能是您想要进行任何更改的地方。

第一行将所有菜单项重置为原始大小:

contents.animate({margin: 20, height: '64%', lineHeight: '63px'}, 300);

第二行放大了选定的菜单项:

$(contents.get(menuItem_place)).stop().animate({margin: 0, height: '100%', lineHeight: '99px'}, 100); 

第三行计算出菜单必须移动多少像素:

menuItem_position = 0 - (menuItem_place * 200);

最后一行实际上将菜单移动到选定的菜单项:

$('#menuContainer').stop().animate({left: menuItem_position + 'px'}, 300);

在该函数中,它使用片段$(contents.get(menuItem_place))来获取当前菜单项的内容,并简单contents地检索所有菜单项的内容。要将选定的菜单项设置为黑色,您可以尝试以下操作:

$(contents.get(menuItem_place)).stop().css('background-color', 'black').show(100);

尽管将其恢复为原始颜色是您仍然需要弄清楚的事情!

于 2013-04-22T19:40:03.033 回答