我试图将包含飞机图像的固定div移动到右侧,并在页面从顶部向下滚动时淡入0。代码在JSFiddle中工作,但不是浏览器
我工作正常的jsfiddle(http://jsfiddle.net/G4t4f/77/),但在我的WordPress网站的页脚。我显然在这里失去了一些东西。这可能不是最好的方法,因为该网站在bootstrap 3.0.3上运行bootstrap.min.js?
<style>
#header-plane {
z-index: 5;
width: 400px;
position: fixed;
right: 550px;
top: 200px;}
</style>
<div id="header-plane">
<img src="http://wp.ccrcc.org/wp-content/themes/ccrcc/images/plane-1.png"
alt="R/C plane" width="400" height="162">
</div>
<div id="footer">
<script type="text/javascript">
$(document).ready(function() {
function flyOut() {
var top = $(document).scrollTop();
if (top < 30) {
$('#header-plane').animate({
'right': '0',
'opacity': 0
}, 'slow', function() {
});
}
}
$(window).scroll(function() {
flyOut();
});
});
</script>
</div>
您是否尝试过将JS包装到文档就绪函数中?取决于WordPress如何组装您的网站,它可能不会执行该代码。 –