Napisałem slider w jQuery , wrzuciłem go na serwer : www.fpga4u.elektroda.eu , zobaczcie sobie na stronie, przy ładowaniu strony obrazki w tym sliderze brzydko się
ładują , ponieważ jeden leży na drugim i to daje taki efekt. Poza tym przy szybkim przełączaniu dziwnie się zachowuje . Co może być tego powodem ?
Oto mój slider w jQuery :
function slideSwitch(mode) { // mode 0 - auto , 1 - right , 2 - left var $active = $('#slideshow IMG.active'); if((mode==0)||(mode==1)) { if ( $active.length == 0 ) $active = $('#slideshow IMG:last'); var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first'); $active.addClass('last-active'); }else { if ( $active.length == 0 ) $active = $('#slideshow IMG:last'); var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:first'); $active.addClass('last-active'); } if(mode==0){ $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); }); }else if((mode==1)||(mode==2)) { $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 400, function() { $active.removeClass('active last-active'); }); } } $(document).ready(function(){ var left_right = $('#slideshow .left , #slideshow .right'); left_right.hide(); // ukrycie paskow lewo - prawo $('#slideshow').hover(function(){ left_right.show(); left_right.css({opacity: 0.0}).animate({opacity: 0.9}, 400); },function(){ left_right.hide(); // ukryj paski po sciemnienu }); var intervalID =0; $(function() { intervalID = setInterval( "slideSwitch(0)", 4000 ); }); $('#slideshow').hover(function(){ clearInterval(intervalID); $('#slideshow .left').on('click',function(){ }); },function(){ intervalID = setInterval( "slideSwitch(0)", 2000 ); }); $('#slideshow .right').on('click',function(){slideSwitch(1);}); $('#slideshow .left').on('click',function(){slideSwitch(2);}); $('#slideshow').on('click',function(){slideSwitch(1);}); });
Wygląd pliku index.html :
<div id="slideshow"> <img src="img/1.jpg" class="active" width="100%" height="100%"/> <img src="img/2.jpg" width="100%" height="100%"/> <img src="img/3.jpg" width="100%" height="100%"/> <img src="img/4.jpg" width="100%" height="100%"/> <img src="img/5.jpg" width="100%" height="100%"/> <img src="img/6.jpg" width="100%" height="100%"/> <img src="img/7.jpg" width="100%" height="100%"/> <img src="img/8.jpg" width="100%" height="100%"/> <img src="img/9.jpg" width="100%" height="100%"/> <img src="img/10.jpg" width="100%" height="100%"/> </div>
Oraz wygląd pliku CSS :
#slideshow { position: relative; height: 408px; width: 544px; float: right; } #slideshow img { position: absolute; top: 0; left: 0; z-index: 8; } #slideshow img.active { z-index: 10; } #slideshow img.last-active { z-index: 9; } #slideshow .left,#slideshow .right { cursor: default; background-color: #333938; color: #e0e2e4; opacity: 0.6; padding-top: 10px; width: 60px; height: 40px; z-index: 11; top: 174px; font-size: 28px; font-weight: bold; text-align: center; transition-property: opacity; transition-duration: 0.4s; transition-timing-function : ease-in; } #slideshow .left { position: absolute; border-top-right-radius:5px; border-bottom-right-radius:5px; -moz-border-top-right-radius:5px; -moz-border-bottom-right-radius:5px; -webkit-border-top-right-radius:5px; -webkit-border-bottom-right-radius:5px; -khtml-border-top-right-radius:5px; -khtml-border-bottom-right-radius:5px; } #slideshow .right { position: relative; left: 484px; border-top-left-radius:5px; border-bottom-left-radius:5px; -moz-border-top-left-radius:5px; -moz-border-bottom-left-radius:5px; -webkit-border-top-left-radius:5px; -webkit-border-bottom-left-radius:5px; -khtml-border-top-left-radius:5px; -khtml-border-bottom-left-radius:5px; } #slideshow .left:hover,#slideshow .right:hover { background-color: #677472; }
Pierwszy problem , z brzydkim ładowaniem , próbowałem ominąć w następujący sposób :
w pliku html ładowany jest tylko 1 obrazek :
<div id="slideshow"> <img src="img/1.jpg" class="active" width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> <img width="100%" height="100%"/> </div>
Pozostałe obrazki są ładowane w tle, jeszcze przed funkcjami o obsługi slidera :
obrazki zapisane są w tablicy , i ładowane są w pętli for , przed funkcjami:
var imgTable = [ 'img/1.jpg', 'img/2.jpg', 'img/3.jpg', 'img/4.jpg', 'img/5.jpg', 'img/6.jpg', 'img/7.jpg', 'img/8.jpg', 'img/9.jpg', 'img/10.jpg' ]; function slideSwitch(mode) { // mode 0 - auto , 1 - right , 2 - left var $active = $('#slideshow IMG.active'); if((mode==0)||(mode==1)) { if ( $active.length == 0 ) $active = $('#slideshow IMG:last'); var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first'); $active.addClass('last-active'); }else { if ( $active.length == 0 ) $active = $('#slideshow IMG:last'); var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:first'); $active.addClass('last-active'); } if(mode==0){ $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); }); }else if((mode==1)||(mode==2)) { $next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 400, function() { $active.removeClass('active last-active'); }); } } $(document).ready(function(){ var left_right = $('#slideshow .left , #slideshow .right'); left_right.hide(); // ukrycie paskow lewo - prawo $('#slideshow').hover(function(){ left_right.show(); left_right.css({opacity: 0.0}).animate({opacity: 0.9}, 400); },function(){ left_right.hide(); // ukryj paski po sciemnienu }); for(var i=1;i<imgTable.length;i++) { $('#slideshow img').eq(i).attr('src',imgTable[i]); } var intervalID =0; $(function() { intervalID = setInterval( "slideSwitch(0)", 4000 ); }); $('#slideshow').hover(function(){ clearInterval(intervalID); $('#slideshow .left').on('click',function(){ }); },function(){ intervalID = setInterval( "slideSwitch(0)", 2000 ); }); $('#slideshow .right').on('click',function(){slideSwitch(1);}); $('#slideshow .left').on('click',function(){slideSwitch(2);}); $('#slideshow').on('click',function(){slideSwitch(1);}); });
Niestety to nie rozwiązało mojego problemu , proszę o fachową pomoc
