[英]How can I implement horizontal scroll on drag functionality on text that has “text-overflow: ellipsis” without the scrollbar?
I have several lines of text, each of them is wrapped inside fixed-width paragraph tag. 我有几行文字,每行都包裹在固定宽度的段落标签内。 They are different in length.
它们的长度不同。 So I truncate the lines with "text-overflow: ellipsis" and hide the scroll-bar with "overflow: hidden".
因此,我用“ text-overflow:省略号”截短了行,并用“ overflow:hidden”隐藏了滚动条。
HTML: HTML:
<p>This is a short line</p>
<p>This line is a little bit longer</p>
<p>This is a really very long very long very long line</p>
<p>This is a short line</p>
<p>This line is a little bit longer</p>
<p>This is a really very long very long very long line</p>
<p>This is a short line</p>
<p>This line is a little bit longer</p>
<p>This is a really very long very long very long line</p>
CSS: CSS:
p {
width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
I would like to be able to scroll on drag to see what the full line is, but without displaying the scroll-bar. 我希望能够在拖动时滚动以查看整行,但不显示滚动条。
Here's a jsfiddle with default scroll-bar, which allows me to do scrolling, and here's a jsfiddle with "overflow: hidden" property, that truncates the lines the way I need, but without scrolling. 这是一个带有默认滚动条的jsfiddle,它允许我进行滚动, 这是一个具有“ overflow:hidden”属性的jsfiddle,它以我需要的方式截断了这些行,但没有滚动。
So, what are possible ways to hide the scroll-bar but keep scroll-on-drag functionality? 那么,隐藏滚动条但保留拖动时滚动功能的可能方法是什么? Can it be done with pure HTML and CSS or I would have to write JS or even jQuery?
可以使用纯HTML和CSS来完成,还是必须写JS甚至jQuery?
Hi I write a simple method for you, You can develope it 嗨,我为您编写了一个简单的方法,您可以进行开发
var clicked = 0;
var regular = 0;
$(document).ready(function(){
$("p").mousedown(function(){
clicked = 1;
regular = 0;
});
$("p").mouseup(function(){
clicked = 0;
});
$("p").mousemove(function(event, a, b){
var p = $(this);
if( event.offsetX > (p.width() - 30) && clicked == 1){
console.log((regular - 1));
regular--;
p.css({"text-indent":(regular) + "px"});
}
if( event.offsetX < 30 && event.offsetX > 0 && clicked == 1){
console.log((regular - 1));
regular++;
p.css({"text-indent":(regular) + "px"});
}
});
});
JSFiddle : http://jsfiddle.net/k4mhohc8/4/ JSFiddle: http : //jsfiddle.net/k4mhohc8/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.