admin管理员组文章数量:1355671
I just found that it is possible to make a very simple slideshow by jQuery as
$(function(){
$('.fadein img:gt(0)').hide();
setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 3000);
});
with
<div class="fadein">
<img src=".jpg">
<img src=".jpg">
<img src=".jpg">
</div>
I wonder how to modify this simple code to make a slide effect (fadeIn/fadeOut) for DIV instead of img
. For example to make a slideshow of
<div class="fadein">
<div><img src=".jpg">Some text</div>
<div><img src=".jpg">Some text</div>
<div><img src=".jpg">Some text</div>
</div>
I just found that it is possible to make a very simple slideshow by jQuery as
$(function(){
$('.fadein img:gt(0)').hide();
setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 3000);
});
with
<div class="fadein">
<img src="http://farm3.static.flickr./2610/4148988872_990b6da667.jpg">
<img src="http://farm3.static.flickr./2597/4121218611_040cd7b3f2.jpg">
<img src="http://farm3.static.flickr./2531/4121218751_ac8bf49d5d.jpg">
</div>
I wonder how to modify this simple code to make a slide effect (fadeIn/fadeOut) for DIV instead of img
. For example to make a slideshow of
<div class="fadein">
<div><img src="http://farm3.static.flickr./2610/4148988872_990b6da667.jpg">Some text</div>
<div><img src="http://farm3.static.flickr./2597/4121218611_040cd7b3f2.jpg">Some text</div>
<div><img src="http://farm3.static.flickr./2531/4121218751_ac8bf49d5d.jpg">Some text</div>
</div>
Share
Improve this question
asked Nov 24, 2011 at 7:57
GooglebotGooglebot
15.7k45 gold badges144 silver badges247 bronze badges
0
3 Answers
Reset to default 4I wrote some code:
$(function(){
$ds = $('.fadein div');
$ds.hide().eq(0).show();
setInterval(function(){
$ds.filter(':visible').fadeOut(function(){
var $div = $(this).next('div');
if ( $div.length == 0 ) {
$ds.eq(0).fadeIn();
} else {
$div.fadeIn();
}
});
}, 3000);
});
Full example code you can find here : http://jsfiddle/h58ng/
I created a simple jQuery plugin:
DEMO - loop plugin
you just need to have a parent for your elements, and set the CSS of your elements to position:absolute;
, and display:none;
The plugin:
(function($){jQuery.fn.loop = function(d,f){var e=this.children();var el=function(i){if(i==e.length)i=0;e.fadeTo(f,0).eq(i).fadeTo(f,1);setTimeout(function(){el(++i);},d);};el(0);};})(jQuery);
// How to use: $('yourElement').loop( delay , fadespeed );
// Ex: $('#myDiv').loop(2500, 400);
Try this
$(function(){
$('.fadein div:gt(0)').hide();
setInterval(function(){$('.fadein :first-child').fadeOut().next('div').fadeIn().end().appendTo('.fadein');}, 3000);
});
本文标签: javascriptA simple jQuery slideshow to work for DIVStack Overflow
版权声明:本文标题:javascript - A simple jQuery slideshow to work for DIV - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744033154a2579285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论