我想将自动幻灯片添加到此脚本中,有人可以帮助我吗?
I want to add auto slide to this script can any one help me out?
嗨,朋友们,我的网站上有一个图片滑块
通过单击预览和下一步按钮来幻灯片图像。
我的问题是:是否可以添加自动启动而不是 onclik?
这是我的代码:
我想在此脚本中添加自动幻灯片,有人可以帮我吗??没有自动播放选项。它只是在鼠标单击事件上滑动。
$(document).ready(function () {
var showCaseItems = $('.show-case-item').hide();
var splashes = $('.splash').hide();
//get each image for each slide and set it as a background of the slide
// splashes.each(function () {
// var img = $(this).find('img');
// var imgSrc = img.attr('src');
// img.css('visibility', 'hidden');
// $(this).css({ 'background-image': 'url(' + imgSrc + ')', 'background-repeat': 'no-repeat' });
// });
splashes.eq(0).show();
showCaseItems.eq(0).show();
var prevIndex = -1;
var nextIndex = 0;
var currentIndex = 0;
$('#banner-pagination li a').click(function () {
nextIndex = parseInt($(this).attr('rel'));
if (nextIndex != currentIndex) {
$('#banner-pagination li a').html('<img src="assets/img/slidedot.png" alt="slide"/>');
$(this).html('<img src="assets/img/slidedot-active.png" alt="slide"/>');
currentIndex = nextIndex;
if (prevIndex < 0) prevIndex = 0;
splashes.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
});
splashes.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 500, function () { });
showCaseItems.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
showCaseItems.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 200, function () { });
});
prevIndex = nextIndex;
}
return false;
});
});
我假设您的 div 中有一个名为横幅分页的 ul。很难看不到你的 html。如果你没有,你应该有。 ul 应该始终包围 lis
jQuery(document).ready(function ($) {
var slideCount = $('#banner-pagination ul li a').length;
var slideWidth = $('#banner-pagination ul li a').width();
var slideHeight = $('#banner-pagination ul li a').height();
var sliderUlWidth = slideCount * slideWidth;
$('#banner-pagination').css({ width: slideWidth, height: slideHeight });
$('#banner-pagination ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });
$('#banner-pagination ul li:last-child').prependTo('#slider ul');
function moveLeft() {
$('#banner-pagination ul').animate({
left: + slideWidth
}, 1000, function () {
$('#banner-pagination ul li:last-child').prependTo('#slider ul');
$('#banner-pagination ul').css('left', '');
});
};
function do_slide(){
interval = setInterval(function(){
moveLeft();
}, 1000);
}
do_slide();
$('ul li').hover(function(){
clearInterval(interval);
});
$('ul li').mouseleave(function(){
do_slide();
});
});
Reference
嗨,朋友们,我的网站上有一个图片滑块
通过单击预览和下一步按钮来幻灯片图像。
我的问题是:是否可以添加自动启动而不是 onclik?
这是我的代码:
我想在此脚本中添加自动幻灯片,有人可以帮我吗??没有自动播放选项。它只是在鼠标单击事件上滑动。
$(document).ready(function () {
var showCaseItems = $('.show-case-item').hide();
var splashes = $('.splash').hide();
//get each image for each slide and set it as a background of the slide
// splashes.each(function () {
// var img = $(this).find('img');
// var imgSrc = img.attr('src');
// img.css('visibility', 'hidden');
// $(this).css({ 'background-image': 'url(' + imgSrc + ')', 'background-repeat': 'no-repeat' });
// });
splashes.eq(0).show();
showCaseItems.eq(0).show();
var prevIndex = -1;
var nextIndex = 0;
var currentIndex = 0;
$('#banner-pagination li a').click(function () {
nextIndex = parseInt($(this).attr('rel'));
if (nextIndex != currentIndex) {
$('#banner-pagination li a').html('<img src="assets/img/slidedot.png" alt="slide"/>');
$(this).html('<img src="assets/img/slidedot-active.png" alt="slide"/>');
currentIndex = nextIndex;
if (prevIndex < 0) prevIndex = 0;
splashes.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
});
splashes.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 500, function () { });
showCaseItems.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
showCaseItems.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 200, function () { });
});
prevIndex = nextIndex;
}
return false;
});
});
我假设您的 div 中有一个名为横幅分页的 ul。很难看不到你的 html。如果你没有,你应该有。 ul 应该始终包围 lis
jQuery(document).ready(function ($) {
var slideCount = $('#banner-pagination ul li a').length;
var slideWidth = $('#banner-pagination ul li a').width();
var slideHeight = $('#banner-pagination ul li a').height();
var sliderUlWidth = slideCount * slideWidth;
$('#banner-pagination').css({ width: slideWidth, height: slideHeight });
$('#banner-pagination ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });
$('#banner-pagination ul li:last-child').prependTo('#slider ul');
function moveLeft() {
$('#banner-pagination ul').animate({
left: + slideWidth
}, 1000, function () {
$('#banner-pagination ul li:last-child').prependTo('#slider ul');
$('#banner-pagination ul').css('left', '');
});
};
function do_slide(){
interval = setInterval(function(){
moveLeft();
}, 1000);
}
do_slide();
$('ul li').hover(function(){
clearInterval(interval);
});
$('ul li').mouseleave(function(){
do_slide();
});
});
Reference