我有两个点击事件,一个是触发页面转换
$('.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();
}
});
我无法设置在轮播点击事件中生成的延迟变量,可以访问页面转换点击事件。
基本上我只需要把这两件事放在一起,有没有比我做的更好的方法呢?
这是网站 - http://stfn.herokuapp.com/ 并且上面的代码片段行是403和1033
答案 0 :(得分:0)
喜欢这个吗?
// define delay in global scope
// delay needs a default value, in case a pt-trigger is clicked before
// using the slider, change 1000 to suit your needs.
var delay = 1000;
// line 403
$('.pt-trigger').click(function() {
$pageTrigger = $(this);
// e.preventDefault();
// console.log('read delay', delay);
setTimeout(function() { Animate($pageTrigger); }, delay);
});
// line 1033
$('.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;
// console.log('set delay', delay);
currentIndex = index;
setTimeout(goToLink, delay);
} else {
// Animate();
}
});
答案 1 :(得分:0)
不确定jquery。但是如果yplain js,尝试拥有一个唯一命名的全局变量,则具有setter和getter访问权限。设置链接到carousel事件的函数,然后进入页面转换事件。
类似的东西:
var carouselTransitionDelay;
function setCarouselTransitionDelay(delay) {
carouselTransitionDelay=delay;
}
function getCarouselTransitionDelay(){
return carouselTransitionDelay;
}