/* * txtscroll - 基于jquery的文本无缝循环滚动插件 * * 作者: obear * 版本: 1.0 * 创建日期: 2018-12-07 * * 使用说明: * { 使用前请引入jquery, 文本长度大于父级元素才可激活滚动,否则无滚动效果 } */ ;(function ($) { "use strict"; $.fn.txtscroll = function (options) { //默认参数 //{ // speed - 滚动间隔时间 //} var settings = $.extend({ 'speed': 50 }, options); return this.each(function () { var $this = $(this); var $settings = settings; var scrollbox = $('.scrollbox',$this); var txt_begin = $('.txt',$this); var txt_end = $('
'); var scrollvaue = 0; function marquee() { if (txt_end.width() - scrollbox.scrollleft() <= 0){ scrollvaue = scrollbox.scrollleft() - txt_begin.width(); scrollbox.scrollleft(scrollvaue); } else{ scrollvaue = scrollvaue + 1; scrollbox.scrollleft(scrollvaue); } } if(txt_begin.width() > scrollbox.width()){ txt_end.html(txt_begin.html()); scrollbox.append(txt_end); var setmarquee = setinterval(marquee, $settings.speed); $this.on('mouseover', function(){ clearinterval(setmarquee); }); $this.on('mouseout', function(){ setmarquee = setinterval(marquee, $settings.speed); }); } }); }; })(jquery);