Advertisement
Guest User

awd

a guest
May 2nd, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Untitled Document</title>
  6.  
  7.  
  8. <style type="text/css">
  9. #header {
  10. -o-transform-origin: 460px 150px;
  11. background: #000000 url("http://www.devirtuoso.com/Examples/jQuery-Animated-Header/background.jpg") repeat-y;
  12. height: 300px;
  13. width: 920px;
  14. }​
  15. </style>
  16.  
  17. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  18. </head>
  19.  
  20. <body>
  21.  
  22.  
  23.  
  24. <script type="text/javascript">
  25. $(function(){
  26. function bgScroller(options) {
  27. var settings = {
  28. containerID: '', //id of the scroller's containing element
  29. scrollSpeed: 50, //Speed in milliseconds
  30. step: 1, //How many pixels to move per step
  31. imageHeight: 0, //Background image height
  32. headerHeight: 0, //How tall the header is.
  33. autoStart: true
  34. };
  35. if(options) {
  36. jQuery.extend(settings, options);
  37. }
  38. var current = 0, // The current pixel row
  39. restartPosition = -(settings.imageHeight - settings.headerHeight), //The pixel row where to start a new loop
  40. interval = null,
  41. $container = jQuery('#' + settings.containerID),
  42. that = {};
  43. if(!$container.length || !settings.imageHeight || !settings.headerHeight) {
  44. return false; //nothing will work without these settings so let's not even try
  45. }
  46. function setBg() {
  47. $container.css("background-position", "0 " + current + "px");
  48. }
  49. function scrollBg(){
  50. current -= settings.step;//Go to next pixel row.
  51. //If at the end of the image, then go to the top.
  52. if (current <= restartPosition){
  53. current = 0;
  54. }
  55. setBg();
  56. }
  57. that.reset = function() {
  58. that.stop();
  59. current = 0;
  60. setBg();
  61. }
  62. that.start = function() {
  63. interval = setInterval(scrollBg, settings.scrollSpeed);
  64. };
  65. that.stop = function(){
  66. clearInterval(interval);
  67. };
  68. that.reset();
  69. if(settings.autoStart) {
  70. that.start();
  71. }
  72. return that;
  73. }
  74.  
  75. var headerScroller = new bgScroller({
  76. containerID: "header",
  77. scrollSpeed: 70,
  78. imageHeight: 4300,
  79. headerHeight: 300,
  80. step: 2,
  81. autoStart: false
  82. });
  83.  
  84. setTimeout(headerScroller.start, 2000);
  85. setTimeout(headerScroller.stop, 6000);
  86. setTimeout(headerScroller.reset, 8000);
  87. ​});
  88.  
  89. </script>
  90.  
  91.  
  92.  
  93. <div id="header"></div>​
  94. </body>
  95. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement