Advertisement
Guest User

test2

a guest
May 11th, 2012
2,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  5.  
  6. <script type="text/javascript">
  7. (function($) {
  8. $.fn.textWidth = function(){
  9. var calc = '<span style="display:none">' + $(this).text() + '</span>';
  10. $('body').append(calc);
  11. var width = $('body').find('span:last').width();
  12. $('body').find('span:last').remove();
  13. return width;
  14. };
  15.  
  16. $.fn.marquee = function(args) {
  17. var that = $(this);
  18. var textWidth = that.textWidth(),
  19. offset = that.width(),
  20. width = offset,
  21. css = {
  22. 'text-indent' : that.css('text-indent'),
  23. 'overflow' : that.css('overflow'),
  24. 'white-space' : that.css('white-space')
  25. },
  26. marqueeCss = {
  27. 'text-indent' : width,
  28. 'overflow' : 'hidden',
  29. 'white-space' : 'nowrap'
  30. },
  31. args = $.extend(true, { count: -1, speed: 1e1, leftToRight: false }, args),
  32. i = 0,
  33. stop = textWidth*-1,
  34. dfd = $.Deferred();
  35.  
  36. function go() {
  37. if(!that.length) return dfd.reject();
  38. if(width == stop) {
  39. i++;
  40. if(i == args.count) {
  41. that.css(css);
  42. return dfd.resolve();
  43. }
  44. if(args.leftToRight) {
  45. width = textWidth*-1;
  46. } else {
  47. width = offset;
  48. }
  49. }
  50. that.css('text-indent', width + 'px');
  51. if(args.leftToRight) {
  52. width++;
  53. } else {
  54. width--;
  55. }
  56. setTimeout(go, args.speed);
  57. };
  58. if(args.leftToRight) {
  59. width = textWidth*-1;
  60. width++;
  61. stop = offset;
  62. } else {
  63. width--;
  64. }
  65. that.css(marqueeCss);
  66. go();
  67. return dfd.promise();
  68. };
  69. $('h1').marquee();
  70. })(jQuery);
  71. </script>
  72. </head>
  73. <body>
  74. <h1>test</h1>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement