简体   繁体   English

如何在彩盒内进行scrollTop?

[英]How to do scrollTop inside a colorbox?

Basically I have lots of content to be shown inside the colorbox plugin, and I want to scroll into certain part by program. 基本上我有很多内容要在colorbox插件中显示,我想按程序滚动到某个部分。

The colorbox part works fine. 彩盒部分工作正常。 The simplified code looks like this (nothing special here): 简化的代码看起来像这样(这里没什么特别的):

$.colorbox({href: '#my_content', inline:true, onComplete(){go_there()}});

The scroll part, if using without colorbox, also works fine. 滚动部分,如果使用没有彩盒,也可以正常工作。 The code looks like this: 代码如下所示:

$('html,body').animate({scrollTop: 1234}, 100); // 1234 here is just example

When combining above two parts, scrolling does not happen. 当组合以上两个部分时,不会发生滚动。 And then I think I need to change the 'html, body' string into something else, so I immediately tried $("#my_content").animate(...) but no luck, and then I tried "#cboxContent", "#cboxWrapper", "#colorbox". 然后我想我需要将'html,body'字符串更改为其他内容,所以我立即尝试$(“#my_content”)。animate(...)但没有运气,然后我尝试了“#cboxContent”, “#cboxWrapper”,“#colorbox”。 None of them works. 它们都不起作用。

(I gonna provide an answer soon.) (我很快就会提供答案。)

After searching around for similar code snippets, I realize a pattern, that the scrollTop must only be applied to one of your content wrappers which has an overflow:auto style! 在搜索类似的代码片段后,我意识到一种模式,即scrollTop必须只应用于一个具有溢出的内容包装器:自动样式!

Correct direction found, I soon check up colorbox.css and identified the wanted container. 找到了正确的方向,我很快检查了colorbox.css并确定了所需的容器。 It is '#cboxLoadedContent'. 它是'#cboxLoadedContent'。 So this one works like a charm: 所以这个就像一个魅力:

$('#cboxLoadedContent').animate({scrollTop: 1234}, 100);

The principle might be straightforward, but it really took me some time to figure out. 原则可能很简单,但我花了一些时间才弄明白。 So hopefully this post can help someone like me. 所以希望这篇文章可以帮助像我这样的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM