Advertisement
Guest User

smooth scrolling

a guest
Jul 29th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.72 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type"content=
  5. "text/html; charset="UTF-8">
  6. <title>Untitled Document</title>
  7. <style type="text/css">
  8. body {
  9.     margin:0;
  10.     font:30px Arial, Helvetica, sans-serif;
  11. }
  12. section {
  13.     background-color: #09C;
  14.     display: block;
  15.     height: 2000px;
  16.     padding:60px;
  17.     padding-left:120px;
  18. }
  19. #one{
  20.     background:#0C2C59;
  21.     color:#FFF;
  22. }
  23. #two{
  24.     background:#04528A;
  25.     color:#FFF;
  26. }
  27. #three{
  28.     background:#279C5C;
  29.     color:#FFF;
  30. }
  31. #four{
  32.     background:#257D2A;
  33.     color:#FFF;
  34. }
  35. #five{
  36.     background:#34631F;
  37.     color:#FFF;
  38. }
  39.  
  40. nav {
  41.     position:fixed;
  42. }
  43. body nav a {
  44.     font-size: 12px;
  45.     color: #FFF;
  46.     background-color: #000;
  47.     text-align: center;
  48.     display: block;
  49.     margin: 3px;
  50.     padding: 10px;
  51. }
  52. </style>
  53.  
  54. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  55.  
  56. <script type="text/javascript">
  57. $(document).ready(function() {
  58.   function filterPath(string) {
  59.   return string
  60.     .replace(/^\//,'')
  61.     .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
  62.     .replace(/\/$/,'');
  63.   }
  64.   var locationPath = filterPath(location.pathname);
  65.   var scrollElem = scrollableElement('html', 'body');
  66.  
  67.   $('a[href*=#]').each(function() {
  68.     var thisPath = filterPath(this.pathname) || locationPath;
  69.     if (  locationPath == thisPath
  70.     && (location.hostname == this.hostname || !this.hostname)
  71.    && this.hash.replace(/#/,'') ) {
  72.      var $target = $(this.hash), target = this.hash;
  73.       if (target) {
  74.         var targetOffset = $target.offset().top;
  75.         $(this).click(function(event) {
  76.           event.preventDefault();
  77.           $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
  78.             location.hash = target;
  79.           });
  80.         });
  81.       }
  82.     }
  83.   });
  84.  
  85.   // use the first element that is "scrollable"
  86.   function scrollableElement(els) {
  87.     for (var i = 0, argLength = arguments.length; i <argLength; i++) {
  88.      var el = arguments[i],
  89.          $scrollElement = $(el);
  90.      if ($scrollElement.scrollTop()> 0) {
  91.         return el;
  92.       } else {
  93.         $scrollElement.scrollTop(1);
  94.         var isScrollable = $scrollElement.scrollTop()> 0;
  95.         $scrollElement.scrollTop(0);
  96.         if (isScrollable) {
  97.           return el;
  98.         }
  99.       }
  100.     }
  101.     return [];
  102.   }
  103.  
  104. });
  105. </script>
  106.  
  107. </head>
  108.  
  109. <body>
  110. <nav><a href="#one">one</a> <a href="#two">two</a> <a href="#three">three</a> <a href="#four">four</a> <a href="#five">five</a></nav>
  111. <section id="one">Page One<p> how do i make this text smaller?</section>
  112. <section id="two">Page Two</section>
  113. <section id="three">Page Three</section>
  114. <section id="four">Page Four</section>
  115. <section id="five">Page Five</section>
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement