Метка: rotator
Полный ресайз бекграунда с плавной заменой изображения
Помните пост Полный ресайз бекграунда не зависимо от размеров окна браузера

Сегодня сделаем так что бы бекграунд еще и с эффектом затухания слайдилась
function backgroundScale()
{
var imageRatio = 1.75;
var windowHeight = document.body.clientHeight;
var windowWidth = document.body.clientWidth;
var windowScale = windowWidth / windowHeight;
var targetWidth = windowHeight * imageRatio;
var targetWidthFull = windowWidth;
var leftPos = - (targetWidth - windowWidth) / 2;
var leftPosFull = 0;
if (windowScale <= imageRatio)
{
$('#rotator img').attr("width", targetWidth);
$('#rotator').css("left", leftPos);
}
else
{
$('#rotator img').attr("width", targetWidthFull);
$('#rotator').css("left", leftPosFull);
}
}
$(window).resize(function()
{
var imageRatio = 1.75;
var windowHeight = document.body.clientHeight;
var windowWidth = document.body.clientWidth;
var windowScale = windowWidth / windowHeight;
var targetWidth = windowHeight * imageRatio;
var targetWidthFull = windowWidth;
var leftPos = - (targetWidth - windowWidth) / 2;
var leftPosFull = 0;
if (windowScale <= imageRatio)
{
$('#rotator img').attr("width", targetWidth);
$('#rotator').css("left", leftPos);
}
else
{
$('#rotator img').attr("width", targetWidthFull);
$('#rotator').css("left", leftPosFull);
}
mainBaseResize();
});
$(document).ready(function(){
//$('body').css({background: #fff});
backgroundScale();
theRotator();
});
А теперь в скрипт добавляем эти функции
function theRotator() {
$('#rotator img').css({opacity: 0.0});
$('#rotator img:first').css({opacity: 1.0});
setInterval('rotate()',7000);
}
function rotate() {
// Берем первую картинку
var current = ($('#rotator img.show')? $('#rotator img.show') : $('#rotator img:first'));
// Берем следующую картинку, когда дойдем до последней начинаем с начала
var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotator img:first') :current.next()) : $('#rotator img:first'));
// Рандом
var sibs = current.siblings();
var rndNum = Math.floor(Math.random() * sibs.length );
var next = $( sibs[ rndNum ] );
// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
// Прячем текущую картинку
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
};
СМОТРЕТЬ РЕЗУЛЬТАТ (Каждые 7 секунд смена бекграунда)
Ротатор изображений вокруг оси на jQuery
Сразу и не придумать где такое можно применить…

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="js/excanvas.js" type="text/javascript"></script>
<script src="js/jquery.imgRotator.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('div.imgRotator').imgRotator();
});
</script>
</head>
<body>
<div class="imgRotator">
<canvas></canvas>
<img src="image.gif" alt="a rotating image" style="width:100px; height:100px"/>
</div>
</body>
</html>
ДЕМО он же офф.сайт откуда можно скачать либу