Ton*_*bet 6 javascript css jquery opacity
那么这个问题有点奇怪,
我有一个网站,其中背景图像随着淡入/淡出过渡而变化
视频:http://www.screenr.com/ZCvs
网络在行动:http://toniweb.us/gm
标记:
<div class="fondo" onclick="descargar(2,500);descargar(1,500);"></div>
<div id="headerimgs">
<div id="headerimg1" class="headerimg"></div>
<div id="headerimg2" class="headerimg"></div>
</div>
<!-- Inicio Cabecera -->
Run Code Online (Sandbox Code Playgroud)
CSS:
.headerimg {
background-position: center top; background-repeat: no-repeat; width:100%;position:absolute;height:100%;cursor:pointer;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.headerimg img{
min-width:100%; width:100%; height:100%;
}
.fondo{
position:absolute;
z-index:1;
width:100%;
height:100%;
cursor:pointer;
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
/*Gestion de pase de imágenes de fondo*/
$(document).ready(function() {
/*controla la velocidad de la animación*/
var slideshowSpeed = 3000;
var transitionSpeed = 2000;
var timeoutSpeed = 500;
/*No tocar*/
var interval;
var activeContainer = 1;
var currentImg = 0;
var animating = false;
var navigate = function(direction) {
// Si ya estamos navegando, entonces no hacemos nada!
if(animating) {
return;
}
currentImg++;
if(currentImg == photos.length + 1) {
currentImg = 1;
}
// Tenemos dos, uno en el que tenemos la imagen que se ve y otro d?nde tenemos la imagen siguiente
var currentContainer = activeContainer;
// Esto puedo optimizarlo con la funci?n modulo, y cambiar 1 y 2 por 0 y 1-> active = mod2(active + 1)
if(activeContainer == 1) {
activeContainer = 2;
} else {
activeContainer = 1;
}
// hay que decrementar el ?ndice porque empieza por cero
cargarImagen(photos[currentImg - 1], currentContainer, activeContainer);
};
var currentZindex = -1;
var cargarImagen = function(photoObject, currentContainer, activeContainer) {
animating = true;
// Nos aseguramos que el nuevo contenedor está siempre dentro del cajon
currentZindex--;
//if(currentZindex < 0) currentZindex=1;
// Actualizar la imagen
$("#headerimg" + activeContainer).css({
"background-image" : "url(" + photoObject + ")",
"display" : "block",
"z-index" : currentZindex
});
// FadeOut antigua
// Cuando la transición se ha completado, mostramos el header
$("#headerimg" + currentContainer).fadeOut(transitionSpeed,function() {
setTimeout(function() {
$("#headertxt").css({"display" : "block"});
animating = false;
}, timeoutSpeed);
});
};
//ver la primera
navigate("next");
//iniciar temporizador que mostrará las siguientes
interval = setInterval(function() {
navigate("next");
}, slideshowSpeed);
});
Run Code Online (Sandbox Code Playgroud)
还有一个叠加div(类fondo)(高度和宽度100%)所以我可以在点击背景时检测到(我不能直接使用背景div,因为转换使它具有负z-index)
问题是这种转变会在所有白色文本中产生奇怪的效果
知道我错过了什么吗?
小智 3
我不知道是什么原因导致您的计算机出现故障,我无法重现它:我在 Windows 7 上使用 IE7、8、9、最新的 Chrome 和 Firefox 进行测试。请向我们提供有关您的设置的更多信息。在测试您自己的网站之前,您是否访问过支持 3D 的网站?这似乎是显卡错误。您是否使用了最新的浏览器和显卡驱动程序?
顺便说一句,您可能需要考虑的是让淡入淡出动画更容易:在初次加载后,它在 Chrome 中会有点卡顿。
可以做到这一点的最简单的动画是 window.setInterval ,执行以下代码:
function(){
var container = $('#headerimgs');
var current = container.children('div:visible:first');
var next = (current.next().length > 1) ? current.next() : container.children('div:visible');
current.fadeOut(300);
next.fadeIn(300);
}
Run Code Online (Sandbox Code Playgroud)
调整一下持续时间以获得您想要的确切效果。请注意,您需要绝对定位 .headerimg div,以便它们完全重叠。