![](/img/trans.png)
[英]Not Working - Header Slide up on scroll down page, and down again on scroll up - jquery
[英]jquery: animate bars on scroll down and again on scroll up
我正在嘗試為正在使用的滾動條上的技能欄設置動畫,但是現在我試圖更進一步,並在向上滾動時將動畫降低。
所以在滾動到330條時將為每個div寬度設置動畫,現在我要在滾動時將其動畫返回0寬度
JS:
> $(document).ready(function(){ $(document).scroll(function() { var top
> = $(document).scrollTop(); console.log(top);
> if (top > 330) {
> $("#html, #css").animate({width:"100%"}, 2000);
> } else {
> $("#html, #css").animate({width:"0%"}, 2000); /* not working */
> }
>
>
> if (top > 330) $("#javascript").animate({width:"70%"}, 2000);
> if (top > 330) $("#php").animate({width:"50%"}, 2000);
> if (top > 330) $("#mysql").animate({width:"30%"}, 2000);
> if (top > 330) $("#wordpress").animate({width:"60%"}, 2000);
> }); });
CSS:
> #height { height:1000px; }
>
> ul {
> list-style-type: none;
> font-family: 'Open Sans';
> color: #787878;
> font-size: 0.8em;
> font-weight: 500;
> font-style: italic;
> line-height: 160%;
> letter-spacing: 1px; }
>
> } li {
> padding: 2px 0 2px 0; }
>
> #html, #css, #javascript, #php, #mysql, #wordpress {
> background-color: #0194bd;
> width: 0%;
> height: 9px;
> margin-bottom: 10px; }
HTML:
<div id="height"></div>
>
> <ul>
> <li>HTML</li>
> <li id="html" class="full"> </li>
> <li>CSS</li>
> <li id="css"></li>
> <li>Javascript</li>
> <li id="javascript"></li>
> <li>PHP</li>
> <li id="php"></li>
> <li>MySQL</li>
> <li id="mysql"></li>
> <li>Wordpress</li>
> <li id="wordpress"></li> </ul>
經過一段時間的if else語句播放后,我意識到我的動畫並沒有停止播放以便恢復到原始大小。
所以我添加了以下內容:
$(document).ready(function(){
$(document).scroll(function() {
var top = $(document).scrollTop();
console.log(top);
if (top > 330) {
$("#html, #css").animate({width:"100%"}, 2000);
} else {
$("#html, #css").stop(true).animate({width:"0"}, '2000'); <--- this line
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.