Skip to content

Instantly share code, notes, and snippets.

@dsebao
Created April 10, 2014 18:50
Show Gist options
  • Save dsebao/10411330 to your computer and use it in GitHub Desktop.
Save dsebao/10411330 to your computer and use it in GitHub Desktop.
Simple Slideimg with jQuery (WP)
<div class="bgslide">
<img src="<?php bloginfo('template_url');?>/images/slide1.png" class="active">
<img src="<?php bloginfo('template_url');?>/images/slide2.png">
</div>
//slidebg
function slideSwitch() {
var $active = $('.bgslide img.active');
if ( $active.length == 0 ) $active = $('.bgslide img:last');
var $next = $active.next().length ? $active.next()
: $('.bgslide img:first');
$active.addClass('last-active').animate({opacity: 0.0}, 1000);
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment