我已经实现了一个在滚动时淡化图像的脚本。
就是这个:
<script type="text/javascript">
// The social div
var $socialDiv,
// The social div's height
socialDivHeight = 500,
currentSocialDivHeight = socialDivHeight;
$(document).ready(function() {
$socialDiv = $('.social');
$socialDiv.css({
'background-image': 'url(http://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/563655_324264884301748_471368753_n.jpg)',
'background-repeat': 'no-repeat',
'background-attachment': 'fixed',
'background-size' : '110% auto',
'height' : socialDivHeight + 'px',
'margin-left' : '-50%',
'margin-right' : '-50%',
'margin-top': '200opx',
});
});
$(window).scroll(function() {
//Get scroll position of window
var windowScroll = $(this).scrollTop();
var newSocialDivHeight = Math.max(0, socialDivHeight - windowScroll);
if (Math.abs(newSocialDivHeight - currentSocialDivHeight) < 1)
return;
$socialDiv.css({
'opacity' : 1 - windowScroll / 400
});
currentSocialDivHeight = newSocialDivHeight;
});
</script>
但是,我试图在上面放置一个 div。并且 z-index 不起作用。
我的分区:
<div style="position: absolute; top: 20px; left: 20px; z-index: 1;">
<img src="http://images5.fanpop.com/image/photos/24600000/Hello-Kitty-Mving-Glittery-Dress-hello-kitty-24617449-320-310.gif" width="119" height="82" />
</div>
我的网站:
http://cargocollective.com/btatest
如果你看右上角,你会看到它。
所以我的问题是;我如何把它带到前面?
谢谢!