2

I am attempting to create an infinite marquee and I have gotten upto this point http://jsfiddle.net/zrW5q/2737/

Firstly; how do I make the text marquee begin on the left side of the browser not the right?

Secondly; How do I stop there being gaps on screen? currently the marquee resets at the end of the h1 text but I want the start of the h1 text to come in from the right as soon as it goes off screen on the left

Finally; How do I keep the text that is hidden from appearing on hover? The text stops on hover but I want the hidden text to stay hidden, currently the hidden text is appearing on hover

JS

 (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);

Any help would be much appreciated, thank you for your time

glittergirl
  • 525
  • 3
  • 17

0 Answers0