Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- (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.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();
- })(jQuery);
- </script>
- </head>
- <body>
- <h1>test</h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement