javascript - Jquery slide down slider -
i trying create slider. here have 3 div's 3 different background color. in following code 3 div's slide down 1 after , slide , runs forever. live here: http://jsfiddle.net/kraditya/egs1br26/3/ want 3 div's slide down 1 after forever. how possible? please help. in advance.
<html> <head> <title>slider</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="../jquery/jquery.min.js"></script> <style> .container{ width: 500px; height: 250px; margin: 0 auto; } .slider1{ width: 500px; height: 250px; margin: 0 auto; //background-image: url(images/image-1.jpg); background-color:yellow; position: absolute; z-index: 1; } .slider2{ width: 500px; height: 250px; margin: 0 auto; //background-image: url(images/image-2.jpg); background-color:green; position: absolute; z-index: 2; } .slider3{ width: 500px; height: 250px; margin: 0 auto; //background-image: url(images/image-3.jpg); background-color:blue; position: absolute; z-index: 3; } </style> <script type="text/javascript"> $(document).ready(function () { var runforever = function () { //$(".slider1").hide(); $(".slider2").hide(); //at start slider2 remains hidden; $(".slider3").hide(); //at start slider3 remains hidden; $(".slider2").slidedown(2000, function () { $(".slider3").slidedown(2000, function () { $(".slider3").slideup(2000, function () { $(".slider2").slideup(2000, runforever); }); }); }); }; runforever(); }); </script> </head> <body> <div class="container"> <div class="slider1"></div> <div class="slider2"></div> <div class="slider3"></div> </div> </body> </html>
http://jsfiddle.net/egs1br26/5/
$(document).ready(function () { var runforever = function () { $(".slider1").hide(); $(".slider2").hide(); //at start slider2 remains hidden; $(".slider3").hide(); //at start slider3 remains hidden; $(".slider1").slidedown(2000, function () { $(".slider2").slidedown(2000, function () { $(".slider3").slidedown(2000,function(){ runforever(); }); }); }); }; runforever(); }); you can add background of container same last slide. seem continuous slidedown.
.container { width: 500px; height: 250px; margin: 0 auto; background-color:blue; } more realistic solution can achieved using z-index. approach, background color container can removed.
var _img=$("#slideshow div"), zindex=99; $(_img).eq(0).show(); function loopit(){ $(_img).eq(1).css('z-index',zindex+1).slidedown(1000,function(){ zindex=zindex+2; $(_img).eq(0).hide(); $(_img).eq(2).css('z-index',zindex).slidedown(1000,function(){ zindex=zindex+3; $(_img).eq(1).hide(); $(_img).eq(0).css('z-index',zindex).slidedown(1000,function(){ $(_img).eq(2).hide(); loopit(); }); }); }) } loopit();
Comments
Post a Comment