向动态内容添加 jQuery 垂直滚动条

发布于 2024-10-06 13:43:10 字数 487 浏览 0 评论 0原文

我正在开发一个网站,我希望主 div 具有固定高度,并带有 jquery 垂直滚动条,以显示溢出该区域的内容。为此,我使用插件 jScrollPane

但是,我想使用插件 zRSSFeed 从 RSS feed 动态加载此内容(我是新用户,所以无法发布 2 个链接!)。

为了做到这一点,我需要像这样调用 rssfeed 函数:

$("#feed").rssfeed(....feed url and options);

然后我想将 jScrollPane 应用于通过调用 rssfeed 函数动态创建的 div。然而,每次我尝试查找 jQuery 元素时,它还不存在。

据我所知,rssfeed 不包含我可以使用的回调函数,并且我尝试在调用 rssfeed 后对 jScrollPane 进行函数链,但这也不起作用。

有什么建议吗?

I'm developing a website and I want the main div to be a fixed height with a jquery vertical scrollbar for content that overflows that area. For this, I'm using the plugin jScrollPane.

However, I want to load this content dynamically from an RSS feed, using the plugin zRSSFeed (I'm a new user so I can't post 2 links!).

In order to do this I need to call the rssfeed function like this:

$("#feed").rssfeed(....feed url and options);

I then want to apply jScrollPane to a div that is dynamically created by calling the rssfeed function. However each time I try to find the jQuery element, it does not yet exist.

As far as I know rssfeed does not include a callback function that I could use, and I have tried to function chain jScrollPane after calling rssfeed, but that did not work either.

Any suggestions??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2024-10-13 13:43:10

必须同意 David 的观点,它还有很多需要改进的地方,但是,或者,您也可以自己为类实现一个回调处理程序:

在 David 建议的同一位置,就在 $(e).html( html); 添加以下内容:

if(options.complete!=null) { options.complete(); }

然后,在您的 html 中:

$(document).ready(function () {
  $('#feed').rssfeed('http://myrssfeedurl', {
    limit: 5,
    complete: function() { $("#feed div").jScrollPane(); }
  });
});

Have to agree with David that it leaves a lot to wish for, but alternatively, you could just implement a callback handler yourself to the class:

In the same place as David suggested, right after the $(e).html(html); add the following:

if(options.complete!=null) { options.complete(); }

Then, in your html:

$(document).ready(function () {
  $('#feed').rssfeed('http://myrssfeedurl', {
    limit: 5,
    complete: function() { $("#feed div").jScrollPane(); }
  });
});
往日情怀 2024-10-13 13:43:10

我快速浏览了 zRSSFeed 插件,代码还有很多不足之处...但是,您也许可以在 _callback 函数的末尾添加自己的触发器,就在 $(e) 之后.html(html); 在脚本的最后。尝试添加:

$(e).trigger('rss');

然后在主程序中,您可以监听元素上的 rss 事件,例如:

$('#feed').bind('rss', function() {
    // the html should now be injected
}).rssfeed( '/stuff.xml' );

它不漂亮,但如果您需要的话,可能是一个快速修复。

I had a quick look at the zRSSFeed plugin and the code leaves a lot to wish for... however, you might be able to add your own trigger in the end of the _callback function, just after the $(e).html(html); at the very end of the script. Try adding:

$(e).trigger('rss');

And then in your main program you can listen for the rss event on the element, like:

$('#feed').bind('rss', function() {
    // the html should now be injected
}).rssfeed( '/stuff.xml' );

It's not pretty but might be a quick-fix if that's what you need here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文