jquery - Make a div childrens appear one by one -
i trying make basic image distributor using jquery.
what have done: when click on empty image, loaded , displayed. demo
$(".pic").click(function() { var src = $(this).attr('rel'); $(this).attr('src', src); });
[edit] want fill every image src in the .pile div, 1 one, each time click on <body>
.
i know need use loop or not confortable that. thank help.
my html content:
<div class="pile"> <img class="pic" rel="3.jpg" src=""/> <img class="pic" rel="2.jpg" src=""/> <img class="pic" rel="1.jpg" src=""/> </div>
i'm not quite sure meant here code have each img appear 1 @ time whenever page clicked.
var $currentimg; $(document).ready(function() { $currentimg = $('#pile img:first'); //get first img pile div $("html").click(function() { var src = $currentimg.attr('rel'); $currentimg.attr('src', src); $currentimg = $currentimg.next(); }); });
this assumes images want in <div>
tag id of pile.
note wrapped original code inside of $(document).ready(function(){ .... });
. testing locally , didn't notice, without thing added page work.
Comments
Post a Comment