首次发布,请耐心等待。幻灯片放映增加了Z指数并减少了不透明度
我试图创建幻灯片是:
- 分配的z-index到每个
<section>
- 将所有幻灯片0.7
- 不透明分配目前上滑块的不透明度1
下面是HTML:
<div id="slides">
<section class="slide">
<article>
<h1>6</h1>
</article>
</section>
<section class="slide">
<article>
<h1>5</h1>
</article>
</section>
<section class="slide">
<article>
<h1>4</h1>
</article>
</section>
<section class="slide">
<article>
<h1>3</h1>
</article>
</section>
<section class="slide">
<article>
<h1>2</h1>
</article>
</section>
<section class="slide">
<article>
<h1>1</h1>
</article>
</section>
</div>
<div id="prev">
<a href="#previous">←</a>
</div>
<div id="next">
<a href="#next">→</a>
</div>
这里是JS至今:
$(document).ready(function() {
var z = 0;
var inAnimation = false;
$('section.slide').each(function() {
z++;
$(this).css('z-index', z);
});
function swapFirstLast(isFirst) {
if(inAnimation) return false;
else inAnimation = true;
var processZindex, direction, newZindex, inDeCrease;
if(isFirst) {
processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1;
} else {
processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1;
}
$('section.slide').each(function() {
if($(this).css('z-index') == processZindex) {
$(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() {
$(this).css('z-index', newZindex)
.animate({ 'top' : '0' }, 'slow', function() {
inAnimation = false;
});
});
} else {
$(this).animate({ 'top' : '0' }, 'slow', function() {
$(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease);
});
}
return false;
}
$('#next a').click(function() {
return swapFirstLast(true);
});
$('#prev a').click(function() {
return swapFirstLast(false);
});
});
});
我想我可以插入下面的代码到脚本:
if($(this).css('z-index') == processZindex) {
$(this).css('opacity', 1);
} else {
$(this).css('opacity', 0.7);
}
的问题是,我似乎不能在1得到的不透明度以跟上Z-index值6.因此,我想写为$(this).css('z-index') != 6
,但问题发生。
有没有更简单的方法来编码?
我有点不清楚你想要什么。你想要幻灯片堆叠?然后用z-index和不透明度来上下拖动?为什么z-index在这里很重要? – 2012-04-17 17:37:17
你的代码似乎有些复杂,正如Jeff B所说,你能更详细地解释你试图达到的效果吗? – trickyzter 2012-04-17 17:45:16
z-index对于我想达到的效果非常重要:幻灯片层位于彼此顶部,幻灯片位于顶部幻灯片稍半透明。就像一大堆煎饼的顶部不透明度为1。 – 2012-04-17 18:46:54