jQuery DIV SlideDown() 调整大小跳转
这似乎与 jQuery slipDown Snap Back Issue 类似,但略有不同。您可以访问此网站并浏览“图片”部分来查看问题。如果您单击相册,内容会加载到框中,但是当调整大小时,它认为它仍然是相同的高度,因此,它会停止在该高度。然后,它会快速跳到正确的高度。有什么想法吗?
var jBody = $("#pics .inner");
var jTitle = $("#pics .title");
$("#pics .album-container a").click( function(e) {
var strURL = $(this).attr("href");
var strName = strURL.substr( strURL.indexOf("name=") + 5 );
jBody.slideUp(100);
$.get(
strURL,
function(strData) {
jTitle.text("Pictures - " + strName);
jBody.html(strData).slideDown(1000, "easeOutBounce");
}
);
e.preventDefault();
} );
$("#pics a.back").click( function(e) {
var strURL = $(this).attr("href");
jBody.slideUp(100);
$.get(
strURL,
function(strData) {
jTitle.text("Pictures");
jBody.html(strData).slideDown(1000, "easeOutBounce");
}
);
e.preventDefault();
} );
This seems to be similar to the jQuery slideDown Snap Back Issue, however slightly different. You can visit this site and browse through the "Pics" section to see the issue. If you click on an album, the content loads inside the box but, when resized, it thinks it's still the same height, so, it stops at that height. Then, it jumps quickly to the correct height afterward. Any ideas?
var jBody = $("#pics .inner");
var jTitle = $("#pics .title");
$("#pics .album-container a").click( function(e) {
var strURL = $(this).attr("href");
var strName = strURL.substr( strURL.indexOf("name=") + 5 );
jBody.slideUp(100);
$.get(
strURL,
function(strData) {
jTitle.text("Pictures - " + strName);
jBody.html(strData).slideDown(1000, "easeOutBounce");
}
);
e.preventDefault();
} );
$("#pics a.back").click( function(e) {
var strURL = $(this).attr("href");
jBody.slideUp(100);
$.get(
strURL,
function(strData) {
jTitle.text("Pictures");
jBody.html(strData).slideDown(1000, "easeOutBounce");
}
);
e.preventDefault();
} );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 jQuery 无法计算容器的实际高度,因为你从未指定高度,并且当你触发动画时,里面的内容可能没有完全加载,如果你添加
它会正常工作,如果如果你需要它更加可调整,你可以使用
min-height
,或者在插入 html 之后和动画之前使用 jQuery 设置高度。如果你想测试它,你可以在设置 html 之后记录
console.log(jBody.height())
,这样你就可以看到元素动画的实际完整高度。The problem is that jQuery can't calculate the actual height of the container because you don't ever specify a height, and the content inside probably isn't fully loaded when you fire the animation, if you add
It will work correctly, if you need it to be more adjustable you could use
min-height
, or set the height with jQuery after the html is inserted and before is animated.If you want to test it you could log
console.log(jBody.height())
after the html is set, so you can see the actual full height the element is being animated to.也许可以测试如下内容:
看看在渲染图像高度之前启动动画是否存在问题。
Maybe test something like:
Just so see if it is an issue with the animation starting before the image heights are rendered.