jQuery carousel - 自动扩展高度

发布于 2024-08-26 08:07:54 字数 447 浏览 9 评论 0原文

我有一个功能性垂直 jquery 轮播,因为我已经调整和修改了此处找到的脚本和示例: http://sorgalla.com/projects/jcarousel/examples/static_vertical.html

我使用文本作为列表项,而不是图像。该脚本使用固定高度样式,我正在尝试合并自动扩展高度功能。根据里内的内容进行折叠和展开。

我尝试了一些 css 的操作,例如将某些元素设置为 height:auto;或高度:100%;但似乎不起作用。

有人会告诉我我应该在哪里集中精力尝试如何根据内容自动展开和折叠吗?我应该调整 javascript 而不是 CSS 吗?

只是寻找洞察力。

I have a functional vertical jquery carousel as i have tweaked and modified the script and example found here: http://sorgalla.com/projects/jcarousel/examples/static_vertical.html

Instead of images, i am using text as list items. this script uses an fixed height style, and i am trying to incorporate an auto expand height feature. To collapse and expand based on the content within the li.

i have tried a few things with the css like setting certain elements to height:auto; or height:100%; but does not seem to work.

would anyone have a tidbit on where i should focus my attempts on how to make this auto expand and collapse based on content? should i be tweaking the javascript and not the CSS?

just looking for insight.

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

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

发布评论

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

评论(2

反差帅 2024-09-02 08:07:55

抱歉罗伊,我认为使用 javascript 可能会被认为是过度和不好的做法,即使它有效。

我会建议托尼应用

   li { display:block; overflow:hidden; width:blabla px;}

然后高度会根据内容强制增加和减少。

Sorry Roy I think using javascript would probably be considered overdoing and bad practice even if it works.

I would suggest that Tony applies

   li { display:block; overflow:hidden; width:blabla px;}

Then the height will be forced to increase and decrease according to the content.

肩上的翅膀 2024-09-02 08:07:54

这取决于您的轮播如何工作,但您可能需要调整 JavaScript。

如果轮播需要固定高度的元素,您可以将内容写入元素,获取高度,然后明确地将元素的高度设置为您刚刚找到的值。这样,高度取决于内容,但它也是固定的而不是流动的,并且您也知道高度的值是多少。

像这样的事情可能会起作用:

var height = $("#my-li").css({'height':'auto'}).html('Some text content').height();
//do any calculations you need with height here
$("#my-li").css({'height':height+'px'})

It depends how your carousel works, but you're likely to need to tweak the javascript.

If the carousel needs elements with fixed heights, you could write content into an element, get the height, and then explicity set the height of the element to be the value you just found. That way the height depends on the content, but it is also fixed rather than fluid and you also know what the value for the height is.

Something like this might work:

var height = $("#my-li").css({'height':'auto'}).html('Some text content').height();
//do any calculations you need with height here
$("#my-li").css({'height':height+'px'})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文