Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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 无限选框js从左到右无间隙_Javascript_Jquery - Fatal编程技术网

Javascript 无限选框js从左到右无间隙

Javascript 无限选框js从左到右无间隙,javascript,jquery,Javascript,Jquery,我试图创造一个无限的字幕,我已经达到这一点 首先;如何使文本框从浏览器的左侧而不是右侧开始 第二;我如何阻止屏幕上出现间隙?目前,字幕在h1文本的末尾重置,但我希望h1文本的开头在离开屏幕左侧时立即从右侧进入 最后,;如何保持隐藏的文本不显示在悬停状态?文本在悬停时停止,但我希望隐藏文本保持隐藏,当前隐藏文本显示在悬停时 JS (函数($){ $.fn.textWidth=函数(){ var calc=''+$(this).text()+''; $('body')。追加(计算); var wid

我试图创造一个无限的字幕,我已经达到这一点

首先;如何使文本框从浏览器的左侧而不是右侧开始

第二;我如何阻止屏幕上出现间隙?目前,字幕在h1文本的末尾重置,但我希望h1文本的开头在离开屏幕左侧时立即从右侧进入

最后,;如何保持隐藏的文本不显示在悬停状态?文本在悬停时停止,但我希望隐藏文本保持隐藏,当前隐藏文本显示在悬停时

JS

(函数($){
$.fn.textWidth=函数(){
var calc=''+$(this).text()+'';
$('body')。追加(计算);
var width=$('body').find('span:last').width();
$('body').find('span:last').remove();
返回宽度;
};
$.fn.marquee=函数(args){
var,该值=$(此值);
var textWidth=that.textWidth(),
偏移量=该.width(),
宽度=偏移量,
css={
“文本缩进”:that.css('text-indent'),
“溢出”:that.css('overflow'),
“空白”:that.css('white-space')
},
marqueeCss={
“文本缩进”:宽度,
“溢出”:“隐藏”,
“空白”:“nowrap”
},
args=$.extend(true,{count:-1,速度:1e1,leftToRight:
false},args),
i=0,
停止=文本宽度*-1,
dfd=$.Deferred();
函数go(){
如果(that.css('overflow')!=“hidden”){
css('text-indent',width+'px');
返回false;
}
如果(!that.length)返回dfd.reject();
如果(宽度==停止){
i++;
if(i==args.count){
css(css);
返回dfd.resolve();
}
if(参数leftToRight){
宽度=文本宽度*-1;
}否则{
宽度=偏移量;
}
}
css('text-indent',width+'px');
if(参数leftToRight){
宽度++;
}否则{
宽度--;
}
设置超时(开始,参数速度);
};
if(参数leftToRight){
宽度=文本宽度*-1;
宽度++;
停止=偏移;
}否则{
宽度--;
}
css(marqueeCss);
go();
返回dfd.promise();
};
//$('h1').marquee();
$(“h1”).marquee();
$(“h1”).mouseover(函数(){
$(此).removeAttr(“样式”);
}).mouseout(函数(){
$(this.marquee();
});
})(jQuery);

任何帮助都将不胜感激,谢谢您的时间

也许,您可以用css3从左到右实现一个字幕,就像这样,这不是我想要的,谢谢
 (function($) {
    $.fn.textWidth = function(){
         var calc = '<span style="display:none">' + $(this).text() + '</span>';
         $('body').append(calc);
         var width = $('body').find('span:last').width();
         $('body').find('span:last').remove();
        return width;
    };

    $.fn.marquee = function(args) {
        var that = $(this);
        var textWidth = that.textWidth(),
            offset = that.width(),
            width = offset,
            css = {
                'text-indent' : that.css('text-indent'),
                'overflow' : that.css('overflow'),
                'white-space' : that.css('white-space')
            },
            marqueeCss = {
                'text-indent' : width,
                'overflow' : 'hidden',
                'white-space' : 'nowrap'
            },
            args = $.extend(true, { count: -1, speed: 1e1, leftToRight: 
false }, args),
            i = 0,
            stop = textWidth*-1,
            dfd = $.Deferred();

        function go() {
            if(that.css('overflow')!="hidden") { 
                that.css('text-indent', width + 'px'); 
                return false;
            }
            if(!that.length) return dfd.reject();
            if(width == stop) {
                i++;
                if(i == args.count) {
                    that.css(css);
                    return dfd.resolve();
                }
                if(args.leftToRight) {
                    width = textWidth*-1;
                } else {
                    width = offset;
                }
            }
            that.css('text-indent', width + 'px');
            if(args.leftToRight) {
                width++;
            } else {
                width--;
            }
            setTimeout(go, args.speed);
        };

        if(args.leftToRight) {
            width = textWidth*-1;
            width++;
            stop = offset;
        } else {
            width--;            
        }
        that.css(marqueeCss);
        go();
        return dfd.promise();
    };
           // $('h1').marquee();
$("h1").marquee();
$("h1").mouseover(function () {     
    $(this).removeAttr("style");
}).mouseout(function () {
    $(this).marquee();
});
})(jQuery);