jquery - 使用 Jquery.dotdotdot 的间歇截断

标签 jquery css asp.net ellipsis jquery-dotdotdot

我正在使用 jquery.dotdotdot 截断轮播图 block 上的冗长文本。截断有时会间歇性地截断小于预期结果。 (例如,将文本截断为 4 行,但在某些时候它只截断为 3 行。)

在我的 CSS 上,我曾经有 4 行的公式是 Max-height = line-height * 4。

感谢任何回复。谢谢。 JS:

$(document).ready(function () { 
                EllipsisConfigFunction($(".module-body.dot-ellipsis"));

    function EllipsisConfigFunction($elements) {
        $elements.each(function () {
            var $element = $(this);
            $element.dotdotdot({
                // configuration goes here
                ellipsis: '... ',

                /*  How to cut off the text/html: 'word'/'letter'/'children' */
                wrap: 'word',

                /*  Wrap-option fallback to 'letter' for long words */
                fallbackToLetter: true,

                /*  jQuery-selector for the element to keep and put after the ellipsis. */
                after: null,

                /*  Whether to update the ellipsis: true/'window' */
                watch: true,

                /*  Optionally set a max-height, can be a number or function.
                    If null, the height will be measured. */
                height: null,

                /*  Deviation for the height-option. */
                tolerance: 0,

                /*  Callback function that is fired after the ellipsis is added,
                    receives two parameters: isTruncated(boolean), orgContent(string). */
                callback: function (isTruncated, orgContent) { },

                lastCharacter: {

                    /*  Remove these characters from the end of the truncated text. */
                    remove: [' ', ',', ';', '.', '!', '?'],

                    /*  Don't add an ellipsis if this array contains
                        the last character of the truncated text. */
                    noEllipsis: []
                }
            });
        });
    }
    });

CSS:

.module-body{
            max-height: 80px;
            overflow: hidden;
            position: relative;
            text-align: left;
            line-height:20px;
        }

最佳答案

由于您尚未发布任何代码,因此我的最佳建议如下:

https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/
https://api.jquery.com/jQuery.trim/
http://stackoverflow.com/a/4637957/5833940

看看这些是否解决了您的问题。

最佳 :)

关于jquery - 使用 Jquery.dotdotdot 的间歇截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36258246/

相关文章:

jquery - 如何使用 JQuery 获得单选按钮选择?

php - 如何在一行中显示 3 个 <li>

html - 水平翻转html和css

css - 更改为可见性 : hidden instead of display:none in datatable processing message

asp.net - 我如何使用asp.net MVC4隐藏URL中的ID

ASP.NET 3.5 自定义 DataPager

Javascript成员变量未定义

css - 用CSS保持左列固定

Asp.Net Core 运行一次功能

php - PHP 插入 mysql 后丢失数据