在“滚动”中设置脚本动画.它只运行一次
On-Scroll animate script. It runs only once
每当用户滚动第二个div时,我都希望运行此脚本。从"内容"div的意义上讲,第二个div.第一个div是头。在"滚动"中设置脚本动画。
<!doctype html>
<head>
<script type="text/javascript">
$(document).ready(function(){
$('.content').scroll(function(){
if ($(this).scrollTop() > 100)
{
$(".header").animate({"height": "300px"},"slow");
}
else
{
$(".header").animate({"height": "100px"},"fast");
}
});
});
</script>
<style>
body{
margin:auto;
overflow:hidden;
background-color:#000;
}
.outer{
width:800px;
border:thin solid;
height:900px;
background-color:#fff;
margin:auto;
}
.wrapper{
width:800px;
position:relative;
z-index:100;
height:900px;
}
.header{
width:800px;
height:300px;
border: thin solid #F00;
background-color:#666;
}
.content{
width:800px;
height:600px;
overflow:scroll;
}
</style>
</head>
<body>
<div class="outer">
<div class="wrapper">
<div class="header"></div>
<div class="content">
<p>Dummy content so that the content makes the div to scroll.</p>
</div>
</div>
</div>
</body>
</html>
每当用户滚动div时,脚本都必须运行。
这是在谷歌Chrome上运行的:http://jsfiddle.net/3kySD/2/我不知道为什么,但在我的FireFox(v22.0)上,它正在工作,但速度非常慢。我只更改了你代码中的一点点内容,这让你认为在我看来它不起作用。。。你做了这个测试:
if ($(this).scrollTop() > 100)
我用这个替换了它,所以当内容div位于顶部时,标题栏将最大,而当您阅读内容div时,标题条将更小:
if ($(this).scrollTop() < 100)
Add.stop()
$(".header").stop().animate({"height": "300px"},"slow");
相关文章:
- 使用每500ms运行一次的jquery函数是个好主意吗
- For循环在Jquery中只运行一次
- 使函数只运行一次(Javascript)
- 更改路由后,运行一次js脚本
- 只运行一次提取的脚本
- 可能只在for循环内部运行一次代码块
- 在Flask中使用.getJSON请求时,只运行一次命令
- 数据互绑定问题:转换器只运行一次,无法绑定元素的 ID
- setInterval 只在对象方法上运行一次
- 如何在 window.setInterval 中每分钟运行一次 getJSON 函数
- Cordova(Ionic):Splashscreen只在Android上运行一次
- jQuery事件将只运行一次
- 如果发现任何数据,如何停止每7秒运行一次的函数
- 计划每60秒运行一次代码
- 事件只运行一次
- MEANIO群集(共4个)对于计划作业仅运行一次
- 为什么AS3 navigationToURL()只运行一次
- 在nodeJS中每小时运行一次调度作业
- 如何一次运行一次循环javascript
- 在for循环中触发onchange事件只运行一次