Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
jQuery在鼠标上方水平滚动文本,以在内容末尾停止_Jquery - Fatal编程技术网

jQuery在鼠标上方水平滚动文本,以在内容末尾停止

jQuery在鼠标上方水平滚动文本,以在内容末尾停止,jquery,Jquery,我正试图使用这个小提琴,但是,我不希望div无限滚动-而是我希望滚动停止一旦文本到达其结束,然后在鼠标上重置它回到原来的位置。我尝试了以下方法: $(function(){ var scroll_text, do_scroll = false; $('div.container').hover( function () { var $elmt = $(this); if ($elmt.find('d

我正试图使用这个小提琴,但是,我不希望div无限滚动-而是我希望滚动停止一旦文本到达其结束,然后在鼠标上重置它回到原来的位置。我尝试了以下方法:

$(function(){
    var scroll_text,
        do_scroll = false;

    $('div.container').hover(
        function () {
            var $elmt = $(this);
            if ($elmt.find('div.title-holder a').width() > 130) {
                scroll_text = setInterval(function(){scrollText($elmt);}, 30);
                do_scroll = true;
            }
        },
        function () {
            if (do_scroll) {
                clearInterval(scroll_text);
                $(this).find('div.title-holder a').css({
                    left: 0
                });
            }
        },
        function (){
            $('div.container').scroll( function() {
                if ( $('div.container').scrollLeft() == ($('div.title-holder a').width() - $('div.container').width())) {
                    do_scroll = false;
                }
            });
        }
    );

    var scrollText = function($elmt){
        var left = $elmt.find('div.title-holder a').position().left - 1;
        left = -left > $elmt.find('div.title-holder a').width() ? $elmt.find('div.title-holder').width() : left;
        $elmt.find('div.title-holder a').css({
            left: left
        });
    };
});

但它不起作用。我如何解决这个问题?

这可以解决问题,根据张贴的小提琴:

//move

$('div.container').hover(function(){
var $elmt = $(this);
$elmt.find('div.title-holder a').animate({
    left: '-'+ ($elmt.find('div.title-holder a').width() - $('.container').width())
  }, 5000);    
});

//and return to 0

$('div.container').mouseleave(function(){
var $elmt = $(this);
$elmt.find('div.title-holder a').animate({
    left: 0
  }, 5000);    
});

谢谢这就是我想要的。