我在此处http://www.edhubdemo.com/wp/的一个网站上设置了一个液体轮播滑块。滑块位于我们的作品和我们的客户区域下方,当前用户可以通过单击下一个/上一个按钮滚动浏览作品。现在我想要做的是每 3 秒后应该触发“点击”功能,以便滑块移动到下 4 组作品本身。我尝试使用触发功能,但我想我无法正确集成它。这是液体轮播 javascript 文件中的代码:
(function($){
$.fn.liquidcarousel = function(options) {
var defaults = {
duration: 10000
};
var options = $.extend(defaults, options);
return this.each(function() {
var divobj = $(this);
$(divobj).css('overflow', 'hidden');
$('> .wrapper', divobj).css('overflow', 'hidden');
$('> .wrapper', divobj).css('float', 'left');
$('> .wrapper > ul', divobj).css('float', 'left');
$('> .wrapper > ul', divobj).css('margin', '0');
$('> .wrapper > ul', divobj).css('padding', '0');
$('> .wrapper > ul', divobj).css('display', 'block');
$('> .wrapper > ul > li', divobj).css('display', 'block');
$('> .wrapper > ul > li', divobj).css('float', 'left');
var visiblelis = 0;
var totallis = $('> .wrapper > ul > li', this).length;
var currentposition = 0;
var additionalmargin = 0;
var totalwidth = 0;
$(window).resize(function(e){
var divwidth = $(divobj).width();
var availablewidth = divwidth;
var heighest = 0;
$('> .wrapper > ul > li', divobj).css("height", "auto");
$('> .wrapper > ul > li', divobj).each(function () {
if ( $(this).outerHeight() > heighest ) {
heighest = $(this).outerHeight();
}
});
$(divobj).height(heighest);
$('> .wrapper', divobj).height(heighest);
$('> .wrapper > ul', divobj).height(heighest);
$('> .wrapper > ul > li', divobj).height(heighest);
var liwidth = $('> .wrapper > ul > li:first', divobj).outerWidth(true);
var originalmarginright = parseInt($('> .wrapper > ul > li', divobj).css('marginRight'));
var originalmarginleft = parseInt($('> .wrapper > ul > li', divobj).css('marginLeft'));
totalwidth = liwidth + additionalmargin;
previousvisiblelis = visiblelis;
visiblelis = Math.floor((availablewidth / liwidth));
if (visiblelis < totallis) {
additionalmargin = Math.floor((availablewidth - (visiblelis * liwidth))/visiblelis);
} else {
additionalmargin = Math.floor((availablewidth - (totallis * liwidth))/totallis);
}
halfadditionalmargin = Math.floor(additionalmargin/2);
totalwidth = liwidth + additionalmargin;
if (visiblelis > previousvisiblelis || totallis <= visiblelis) {
currentposition -= (visiblelis-previousvisiblelis);
if (currentposition < 0 || totallis <= visiblelis ) {
currentposition = 0;
}
}
$('> .wrapper > ul', divobj).css('marginLeft', -(currentposition * totalwidth));
if (visiblelis >= totallis || ((divwidth >= (totallis * liwidth)) && options.hidearrows) ) {
if (options.hidearrows) {
$('> .prev', $(divobj).parents(".widget")).hide();
$('> .next', $(divobj).parents(".widget")).hide();
additionalmargin = Math.floor((divwidth - (totallis * liwidth))/totallis);
halfadditionalmargin = Math.floor(additionalmargin/2);
totalwidth = liwidth + additionalmargin;
$('> .wrapper > ul > li', divobj).css('marginRight', originalmarginright + halfadditionalmargin);
$('> .wrapper > ul > li', divobj).css('marginLeft', originalmarginleft + halfadditionalmargin);
}
$('> .wrapper', divobj).width(totallis * totalwidth);
$('> ul', divobj).width(totallis * totalwidth);
$('> .wrapper', divobj).css('marginLeft', 0);
currentposition = 0;
} else {
$('.prev', $(divobj).parents(".widget")).show();
$('.next', $(divobj).parents(".widget")).show();
$('> .wrapper', divobj).width(visiblelis * totalwidth);
$('> ul', divobj).width(visiblelis * totalwidth);
}
});
$('.next', $(divobj).parents(".widget")).click(function(){
if (totallis <= visiblelis) {
currentposition = 0;
} else if ((currentposition + (visiblelis*2)) < totallis) {
currentposition += visiblelis;
} else if ((currentposition + (visiblelis*2)) >= totallis -1) {
currentposition = totallis - visiblelis;
}
$('> .wrapper > ul', divobj).stop();
$('> .wrapper > ul', divobj).animate({'marginLeft': -(currentposition * totalwidth)}, options.duration);
$('.prev', $(divobj).parents(".widget")).click(function(){
if ((currentposition - visiblelis) > 0) {
currentposition -= visiblelis;
} else if ((currentposition - (visiblelis*2)) <= 0) {
currentposition = 0;
}
$('> .wrapper > ul', divobj).stop();
$('> .wrapper > ul', divobj).animate({'marginLeft': -(currentposition * totalwidth)}, options.duration);
});
$('.next', $(divobj).parents(".widget")).dblclick(function(e){
e.preventDefault();
clearSelection();
});
$('.prev', $(divobj).parents(".widget")).dblclick(function(e){
e.preventDefault();
clearSelection();
});
function clearSelection() {
if (document.selection && document.selection.empty) {
document.selection.empty();
} else if (window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}
$(window).resize();
});
这是单击下一个按钮时向前移动滑块的代码部分:
$('.next', $(divobj).parents(".widget")).click(function(){
if (totallis <= visiblelis) {
currentposition = 0;
} else if ((currentposition + (visiblelis*2)) < totallis) {
currentposition += visiblelis;
} else if ((currentposition + (visiblelis*2)) >= totallis -1) {
currentposition = totallis - visiblelis;
}
$('> .wrapper > ul', divobj).stop();
$('> .wrapper > ul', divobj).animate({'marginLeft': -(currentposition * totalwidth)}, options.duration);
这是在单击上一个按钮时使滑块向后移动的代码部分:
$('.prev', $(divobj).parents(".widget")).click(function(){
if ((currentposition - visiblelis) > 0) {
currentposition -= visiblelis;
} else if ((currentposition - (visiblelis*2)) <= 0) {
currentposition = 0;
}
$('> .wrapper > ul', divobj).stop();
$('> .wrapper > ul', divobj).animate({'marginLeft': -(currentposition * totalwidth)}, options.duration);
});