topu

jquery code sample

Jul 19th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.87 KB | None | 0 0
  1. //accordion functionality and animation
  2. $('.toggle-container').hide();
  3. $('.toggle-container').each(function () {
  4.     var $container = $(this);
  5.     var $open = $container.siblings('.open-profile');
  6.     var $close = $container.find('.close-profile');
  7.     var $closelink = $('.close-link');
  8.  
  9.     $open.on('click', function (e) {
  10.         e.preventDefault();
  11.         openSlider($container);
  12.     });
  13.     $close.on('click', function (e) {
  14.         e.preventDefault();
  15.         closeSlider($container, $open);
  16.     });
  17.     $closelink.on('click', function (e) {
  18.         e.preventDefault();
  19.         closeSlider($container, $open);
  20.     });
  21. });
  22.  
  23. function openSlider($container) {
  24.     $('#eligibility-form').show();
  25.     $container.slideDown('fast');
  26.     $('#having-trouble').css('visibility', 'visible');
  27.  
  28.     /*scroll the page to to the form section*/
  29.     $('html,body').animate({
  30.         scrollTop: $("div#panel1").offset().top
  31.     }, 500);
  32.     /*--------------------------------------*/
  33. }
  34.  
  35. function closeSlider($container, $open) {
  36.     $container.slideUp('fast', function () {
  37.         $('#form_wrapper').find('form').css('left', '0').hide();
  38.         $('#form_wrapper').css('left', '0');
  39.  
  40.         //TODO: clear all form fields
  41.  
  42.         $('#having-trouble').css('visibility', 'hidden')
  43.         $open.show();
  44.  
  45.         /*scroll the page to to the top*/
  46.         $('html,body').animate({
  47.             scrollTop: $("body").offset().top
  48.         }, 500);
  49.         /*-----------------------------*/
  50.  
  51.     });
  52. }
  53.  
  54.  
  55. /*if the panel is open on document load, scroll to the panel*/
  56. $(document).ready(function () {
  57.     if ($("div#panel1").css("display") == "block") {
  58.         /*scroll the page to to the form section*/
  59.         $('html,body').animate({
  60.             scrollTop: $("div#panel1").offset().top
  61.         }, 500);
  62.         /*--------------------------------------*/
  63.     }
  64. })
Advertisement
Add Comment
Please, Sign In to add comment