jquery - 将溢出文本滚动到 View 中

标签 jquery css scroll overflow

我需要将一些溢出的文本滚动到 View 中。

我试图为其文本缩进设置动画,但我需要为正确数量的像素设置动画。我该如何计算?

参见:http://jsfiddle.net/wqRcK/5/

我只需要将文本滚动到 View 中,而不是像我尝试的那样滚动“总宽度”。

作为一个附带问题,如何使 span.title 尊重 10 像素填充?

最佳答案

span 设置为 inline-block
并将其动画化为 "-"+ ( $(this).width() - $(this).parent().width() ) + "px":

div.box span.title { white-space: nowrap; display: inline-block; }
$(document).ready(function() {
    var boxwidth = $("div.box").width();
    $("span.title").hover(
      function () {
        $(this).stop().animate({
            textIndent: "-" + ( $(this).width() - $(this).parent().width() ) + "px"  
        }, 1000);  
      }, 
      function () {
        $(this).stop().animate({
            textIndent: "0"           
        }, 1000);  
      }
    );
});

这是你的 fiddle :http://jsfiddle.net/wqRcK/20/

<小时/>

P.S.请记住始终缓存您的选择器。

关于jquery - 将溢出文本滚动到 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9890719/

相关文章:

javascript - 通过我自己的类克隆另一个元素的内容和顺序

jquery - `a > b`是什么意思?

javascript - JQuery slider 位置

javascript - 机车滚动如何让元素固定在滚动条上

python - 将 bootstrap 与 Flask 一起使用时,自定义 css 不起作用

javascript - 在 d3.js 时间线图表中添加图像而不是点

javascript - 选择更改时阻止多个选择滚动到顶部

jquery事件导致窗口刷新

javascript - 在 DropDownlist 中滚动自定义

jquery - Jasmine Clock 模拟和 JQuery 效果 'complete' 功能不能很好地配合