admin管理员组文章数量:1295861
I have navigation nested in a div that is offscreen to the left and when the user scrolls down the page and reaches pixel 296, the left navigation slowly appears by it's width growing towards the right.
What I have now is half working. The navigation nested in the div appears when the user scrolls down the page but I want it to animate slowly to the right and that is not happening. Not sure what I am doing wrong. The specific line I am having problems with is:
$("#slidebottom").animate({ width: "100" }, 'slow');
But here is my entire code:
$(window).scroll(function(){
var wintop = $(window).scrollTop(), docheight = $(document).height(),
winheight = $(window).height();
var bottomHeight = $("#slidebottom").height();
var zeroheight = 0;
if (wintop > 296) {
bottomHeight = $('#slidebottom').height(docheight);
$("#slidebottom").animate({ width: "100" }, 'slow');
}
if( wintop < 296)
{
bottomHeight = $('#slidebottom').height(zeroheight);
//$("#slidebottom").animate({ width: "0" }, 'slow');
}
});
I have navigation nested in a div that is offscreen to the left and when the user scrolls down the page and reaches pixel 296, the left navigation slowly appears by it's width growing towards the right.
What I have now is half working. The navigation nested in the div appears when the user scrolls down the page but I want it to animate slowly to the right and that is not happening. Not sure what I am doing wrong. The specific line I am having problems with is:
$("#slidebottom").animate({ width: "100" }, 'slow');
But here is my entire code:
$(window).scroll(function(){
var wintop = $(window).scrollTop(), docheight = $(document).height(),
winheight = $(window).height();
var bottomHeight = $("#slidebottom").height();
var zeroheight = 0;
if (wintop > 296) {
bottomHeight = $('#slidebottom').height(docheight);
$("#slidebottom").animate({ width: "100" }, 'slow');
}
if( wintop < 296)
{
bottomHeight = $('#slidebottom').height(zeroheight);
//$("#slidebottom").animate({ width: "0" }, 'slow');
}
});
Share
edited Aug 12, 2013 at 23:21
Chad Levy
10.1k8 gold badges43 silver badges69 bronze badges
asked Aug 12, 2013 at 23:19
Ramona SoderlindRamona Soderlind
2132 silver badges13 bronze badges
2 Answers
Reset to default 7The jQuery docs show ints, not strings, as the arguments to width:
$("#slidebottom").animate({ width: 100 }, 'slow');
Edit: So I was wrong, that's not the problem; it handles strings just as well.
Try the following maybe?
$("#slidebottom").animate({ width: '100px' }, 'slow');
I have a feeling that the unit is important for this, since 100 can mean anything. Not very specific. And you can define this as a string just fine. In fact, in the example they give for .animate
it is defined as a string.
本文标签: javascriptHow to animate the width of a div slowly with jqueryStack Overflow
版权声明:本文标题:javascript - How to animate the width of a div slowly with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628167a2389200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论