jQuery 轮播滚动
我刚刚从教程中摘取了这个脚本。它完成了我需要的一切 - 在多个幻灯片和可选择的“当前”上进行操作,
但是它确实有一个错误,如果步骤中的幻灯片少于步骤数量,则它根本不会步进。
<script language="javascript">
jQuery(function() {
var step = 8;
var current = 10;
var maximum = jQuery('#thumb-nav-inner ul li').size();
var visible = 8;
var speed = 500;
var liSize = 114;
var carousel_height = 93;
var ulSize = liSize * maximum;
var divSize = liSize * visible;
jQuery('#thumb-nav-inner ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");
jQuery('#thumb-nav-inner').css("width", divSize+"px").css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
jQuery('#right-thumb-scroll').click(function() {
if(current + step < 0 || current + step > maximum - visible) {return; }
else {
current = current + step;
jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
jQuery('#left-thumb-scroll').click(function() {
if(current - step < 0 || current - step > maximum - visible) {return; }
else {
current = current - step;
jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
});
有人能帮忙解决这个问题吗?
谢谢你们!
I just pinched this script from a tutorial. It does everything i need - steps along at multiple slides and selectable 'current'
It does however have an error whereby, if the step there are less slides than the step amount, it will not step at all.
<script language="javascript">
jQuery(function() {
var step = 8;
var current = 10;
var maximum = jQuery('#thumb-nav-inner ul li').size();
var visible = 8;
var speed = 500;
var liSize = 114;
var carousel_height = 93;
var ulSize = liSize * maximum;
var divSize = liSize * visible;
jQuery('#thumb-nav-inner ul').css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute");
jQuery('#thumb-nav-inner').css("width", divSize+"px").css("height", carousel_height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
jQuery('#right-thumb-scroll').click(function() {
if(current + step < 0 || current + step > maximum - visible) {return; }
else {
current = current + step;
jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
jQuery('#left-thumb-scroll').click(function() {
if(current - step < 0 || current - step > maximum - visible) {return; }
else {
current = current - step;
jQuery('#thumb-nav-inner ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
});
Can anyone help with fixing this?
Thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还没有测试过这个,但我认为错误在于
current + step >最大-可见
和当前-步>最大 - 可见
。如果可用的项目少于可见的项目,它将始终返回 true,因此不会执行步骤!您应该计算这些情况的最小值和最大值,该值应该是Math.min(maximum, max -visible)
。Haven't tested this, but I think the error lies with
current + step > maximum - visible
andcurrent - step > maximum - visible
. If there are less items available than should be visible it will always return true and thus not step! You should calculate a minimum and maximum value for those situations, which should beMath.min(maximum, maximum - visible)
.