【发布时间】:2017-01-06 19:04:27
【问题描述】:
我有两个点击事件,一个是触发页面转换
$('.pt-trigger').click(function() {
$pageTrigger = $(this);
// e.preventDefault();
setTimeout(function() { Animate($pageTrigger); }, delay);
});
另一个动画轮播
$('.carousel .item').click(function(e) {
var index = $(this).index('li');
carousel.cycleActiveTo(index);
e.preventDefault();
if (currentIndex != index) {
var difference;
if (currentIndex == 0 && index >= 5) {
difference = (index - currentIndex) - 13;
} else {
difference = index - currentIndex;
}
difference = Math.abs(difference);
delay = difference * options.duration;
currentIndex = index;
setTimeout(goToLink, delay);
// console.log(delay);
} else {
// Animate();
}
});
我无法使轮播点击事件中生成的delay变量可以被页面转换点击事件访问。
基本上我只需要将这两件事一起计时,有没有比我现在做的更好的方法?
这是网站 - http://stfn.herokuapp.com/ 而上面sn-ps的代码行是403和1033
【问题讨论】:
-
在点击处理程序之外声明
var delay有什么问题? - 还要注意您正在更新window.delay但在setTimeout(...)中使用delay- 这两个不一样 -
关于下一个问题,您能否扩展您的“需要将这两件事一起计时”? - 我不确定我是否理解你想要完成的事情(但使用
timeouts链接事件通常是错误的方法) -
我看到您正在使用
options对象来设置options.duration。为什么不将延迟作为属性添加到您的选项options.delay。这会很清楚。 -
ochi,在点击处理程序之外声明延迟不起作用,因为延迟时间对于每个被点击的元素都是唯一的
标签: jquery variables scope onclick global-variables