Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery获取CSS多列中可见列的文本_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript jquery获取CSS多列中可见列的文本

Javascript jquery获取CSS多列中可见列的文本,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我使用CSS Multicolumn来显示html文件,列的宽度设置为窗口的宽度,因此一次只显示一列_windowWidth=$window.innerWidth。列的高度也设置为窗口的高度_windowHeight=$window.innerHeight。在css中,容器的溢出是隐藏的溢出:隐藏 我可以用$'content'更改可见列.css{-webkit transform:translate+-1*\u column*\u windowWidth+\u columnGap+px,0px}

我使用CSS Multicolumn来显示html文件,列的宽度设置为窗口的宽度,因此一次只显示一列_windowWidth=$window.innerWidth。列的高度也设置为窗口的高度_windowHeight=$window.innerHeight。在css中,容器的溢出是隐藏的溢出:隐藏

我可以用$'content'更改可见列.css{-webkit transform:translate+-1*\u column*\u windowWidth+\u columnGap+px,0px}

我想要的是获取当前可见的列文本

$'content'。子项:visible.text;返回所有列文本

我找到的最接近的问题和答案是:,他建议这个函数:

var getAllTextInColumn = function(rect){
    /*
        rect should be the size and x,y of the column
        { top, left, width, height }
    */

    if(document.caretRangeFromPoint){
        var caretRangeStart = document.caretRangeFromPoint(rect.left, rect.top);
        var caretRangeEnd = document.caretRangeFromPoint(rect.left+rect.width-1, rect.top+rect.height-1);
    } else {
        return null;
    }

    if(caretRangeStart == null || caretRangeEnd == null) return null;

    var range = document.createRange();
    range.setStart(caretRangeStart.startContainer, caretRangeStart.startOffset);
    range.setEnd(caretRangeEnd.endContainer, caretRangeEnd.endOffset);

    return range.toString();
};
但我不知道如何得到列的矩形,例如第3列

任何帮助都将不胜感激

提前通知tnx

更新:

这个函数确实可以工作,但我不能理解它的参数,如果我传递left=0,top=0,width=\u windowWidth,height=\u windowHeight,它会给我第一列的文本

如果我传递left=\u column*\u windowWidth+\u columnGap,top=0,width=\u windowWidth,height=\u windowHeight和_column为0或1,则给出第一列的文本,如果_column>2,则caretRangeStart将为空


如果我传递left=0,top=0,width=\u column*\u windowWidth+\u columnGap+\u windowWidth,height=\u windowHeight,则caretRangeEnd将变为null,因此我无法使其与任何组合一起工作,可能有人可以帮助我。

根据您的描述,您并没有真正隐藏或显示您的列。基本上,您正在更改x偏移

你应该反过来做:得到x偏移量,然后除以-\u windowWidth+\u columnGap

要获取文本,请尝试:


$'content'.children.eqindex.text

它给了我当前的列号,我想要当前列中的文本!在您编辑的答案中,索引与列无关,它指的是第3段或第4段等等。。