jQuery에서 마우스를 이미지 위로 가져 가면 위/아래로 속도가 빨라지는 이미지 슬라이드 쇼를 작성했습니다.jQuery 이미지 캐 러셀 - 어떻게 이미지를 반복 할 수 있습니까?
나는 슬라이드 쇼가 끝나는대로 이미지 '반복'을 가지고 싶습니다. 따라서 사용자가 슬라이드 쇼를 스크롤하면 이미지 LI의 끝 부분에 도달 한 다음 처음부터 원활하게 반복됩니다.
jQuery를
$(document).ready(function()
{
$('#products ul').css('width', ($('#products ul li').length * 185));
var $products = $('#products div');
var posLeft = 0;
// Add 5 DIV overlays to use as 'hover buttons' for the slideshow speed
for (i = 0; i <= 4; i++)
{
$('#products').append('<div class="hover-' + i + '" style="background: transparent; width: 100px; height: 167px; position: absolute; left: ' + posLeft + 'px; top: 15px;"></div>');
posLeft += 100;
}
// Function animate the scrolling DIV in the appropriate direction with the set speed
function plz2scroll(direction, scrollSpeed)
{
var scrollDir = (direction == 'left') ? '-=' : '+=';
var scrollOffset = (direction == 'right') ? '-10' : '+' + $products.css('width').substring(0, -2) + 10; // Fix the '+100px10' issue - Seems substring don't support negative offsets
$products.animate({scrollLeft: scrollDir + $products.css('width')}, scrollSpeed, 'linear', function()
{
$products.scrollLeft(scrollOffset);
plz2scroll(direction, scrollSpeed);
});
}
// Create the 'hover buttons'
$('div.hover-0').hover(function() { $products.stop(); plz2scroll('right', 2000); });
$('div.hover-1').hover(function() { $products.stop(); plz2scroll('right', 3500); });
$('div.hover-2').hover(function() { $products.stop(); });
$('div.hover-3').hover(function() { $products.stop(); plz2scroll('left', 3500); });
$('div.hover-4').hover(function() { $products.stop(); plz2scroll('left', 2000); });
});
HTML
<div id="products">
<div>
<ul>
<li><img src="images/1.jpg" /></li>
<li><img src="images/2.jpg" /></li>
<li><img src="images/3.jpg" /></li>
<li><img src="images/4.jpg" /></li>
<li><img src="images/5.jpg" /></li>
</ul>
</div>
</div>
스크롤러 작품과 속도/방향이 오버레이 DIV 버튼으로 잘 작동 :
여기에 현재 코드입니다. > .stop의/
내 남용()도 잠재적 인 문제처럼 보이는 : 반복 내 애니메이션() 콜백이 느리고 버그 그냥 나쁘다. <
어떤 아이디어가?
나는 반복 문제에 대한 답변을하지 않습니다,하지만 난()', 즉 잘 보이는 당신은'정지를 과도하게 생각하지 않습니다. '100px10'문제는'innerWidth()'와'outerWidth()'를 사용함으로써 극복 될 수 있다고 생각합니다. –
나는'를 선택했다 (으로 parseInt ($의 products.css ('폭'))) '', + 10 ('PX'를 대체합니다.)' – dave
자동 회전 무한 JQuery와 회전 목마와 [도움말 "이 대답을 통해 같은데 . '되감기'대신 회전식 컨베이어를 무한 루프로 만들 수는 없습니다.] [1] "사용할 수 있습니다. [1] : http://stackoverflow.com/questions/3738640/help-with-auto-rotating-infinite-jquery-carousel-can-not-get-carousel-to-loop-in/ 3739493 # 3739493 – bengusty