【发布时间】:2013-03-13 07:28:36
【问题描述】:
我的幻灯片出现了不稳定的行为。它由用户点击的寻呼机驱动。当点击相应的寻呼机时,下一个图像可见(不透明度/过滤器)并设置为 z-index 5,以便它应该位于当前图像下方(z-index 10)。当前图像然后淡出,最后,下一个图像设置为当前,并且已淡出的图像设置为 z-index 0。但是,这仅在单击返回上一个图像时有效(在 Chrome 中,即行为更加奇怪。)按图像顺序排列。也就是说,
- 铬:
- “list_slide1”到“list_slide3”即时跳转,不褪色
- “list_slide3”到“list_slide1”渐变行为正确
- 那么...
- “list_slide1”到“list_slide3”即时跳转不褪色“list_slide3”到
- “list_slide2”淡入淡出行为正确
- 或...
- “list_slide1”到“list_slide6”即时跳转不褪色
- “list_slide6”到任何前面的 list-slide1-5 淡入淡出行为正确
- IE:
- “list_slide1”到“list_slide3”即时跳转,不褪色
- “list_slide3”到“list_slide1”第二次暂停然后跳转
寻呼机和图像是从数据库动态生成的(因此是代码底部的一小段 PHP)。它包含与数据库中页面列出的一样多的项目。
一些注意事项:
1) 淡入淡出功能是我自己的看法 http://javascript.info/tutorial/animation 并且工作得很好 网站其他地方的另一个幻灯片。
2) getElementsByClass 来自http://www.robertnyman.com 并返回 数组中请求类的父元素和子元素(因此 为什么我调用 current[0] 等)
谢谢。
<script type="text/javascript">
var pager = document.getElementById('pager1');
var list_pagers = document.getElementById('pagers')
var i = 0;
var next_slide = function(next) {
if (next.className !== 'slide_current') {
if (getElementsByClassName('slide_pending').length === 0) {
var current = getElementsByClassName('slide_current');
next.className = 'slide_pending';
next.style.zIndex = 5;
next.style.opacity = 1;
next.style.filter = 'alpha(opacity = 100)';
next.style.display = 'block';
fade(current[0], linear, 1000);
var fadeSlide = switcher(next, current);
}
}
}
var switcher = function(now, then) {
setTimeout(function() {
now.className = 'slide_current';
now.style.zIndex = 10;
now.style.opacity = 1;
now.style.filter = 'alpha(opacity = 100)';
then[0].className = 'slide_hide';
then[0].style.zIndex = 0;
then[0].style.opacity = 0;
then[0].style.filter = 'alpha(opacity = 0)';
then[0].style.display = 'none';
}, 1001);
}
<?php
// dynamically build event for each pager/slide in the show.
for ($k = 1; $k <= $i; $k++) {
echo 'var next_slide' .$k. ' = document.getElementById("list_slide" +' .$k. '); ',
'addEvent(list_pagers.childNodes[' .($k - 1). '], "click", function () {next_slide(next_slide' .$k. ')}); ';
}
?>
【问题讨论】:
-
添加淡入淡出(next, linear, 1000, 'in'); ('in' 运行动画以淡入而不是淡出)。帮助 chrome 版本。 IE 中仍然存在不稳定的行为。我认为这与为具有多个子元素的设置动画有关...
标签: javascript css slideshow