Advertisement
here2share

HTML_snap2hscroll ZZZ

Aug 11th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.62 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>scroll test</title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  7. <script>
  8. $(document).ready(function(){
  9. $('div.section').first();
  10. $('a.display').on('click', function(e) {
  11. e.preventDefault();
  12. var t = $(this).text(),
  13. that = $(this);
  14. if (t === 'next' && $('.current').next('div.section').length > 0) {
  15. var $next = $('.current').next('.section');
  16. var top = $next.offset().top;  
  17. $('.current').removeClass('current');
  18. $('body').animate({
  19. scrollTop: top    
  20. }, function () {
  21. $next.addClass('current');
  22. });
  23. } else if (t === 'prev' && $('.current').prev('div.section').length > 0) {
  24. var $prev = $('.current').prev('.section');
  25. var top = $prev.offset().top;
  26. $('.current').removeClass('current');
  27. $('body').animate({
  28. scrollTop: top    
  29. }, function () {
  30. $prev.addClass('current');
  31. });
  32. }
  33. });
  34. });
  35. </script>
  36. <style type="text/css">
  37. p{
  38.     margin-left:40px;
  39. }
  40. .section {background-color:gray; height:440px; margin-bottom:20px; margin-left:80px}
  41. .navigation {position:fixed; left:30px; top:20px;}
  42.  
  43. #c1 {background-color: #FF0000;}
  44. #c2 {background-color: #0000FF;}
  45. #c3 {background-color: #FFD700;}
  46. #c4 {background-color: #308014;}
  47. </style>
  48. </head>
  49. <body>
  50. <div class="main">
  51. <div class="navigation">
  52. <a href="#" class="display">next</a><br>
  53. <a href="#" class="display">prev</a>
  54. </div>
  55. <div id="c1" class="section current">
  56. <p><br>One</p>
  57. </div>
  58. <div id="c2" class="section">
  59. <p><br>Two</p>
  60. </div>
  61. <div id="c3" class="section">
  62. <p><br>Three</p>
  63. </div>
  64. <div id="c4" class="section">
  65. <p><br>Four</p>
  66. </div>
  67. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement