0

I'm trying to imitate the effect on this website when you click the "RSVP" link. The effect is a hidden DIV effect where if you click the RSVP link, the main menu will come down and reveal the hidden DIV.

Here is my website.

I have tried to copy the structure of the div's and JQuery exactly, but no luck so far. All the RSVP link does is scroll the website up, but I need it to push the header down so the other div will show up. I matched all of the ID's with the JQuery so I am at a loss. I am a beginner with JQuery so I am not sure if I need to change anything. Here is the Header.php that is calling the JQuery. Sorry guys this is my first time using Stack so I don't know if I was supposed to paste in all of my source code.

If you use firebug to disable the 'top:-115px;' css line you should be able to see what is supposed to appear:

#header {top: -115px !important;}

Also, it might be worth mentioning that this is a wordpress theme so the structure is made up of .php pages.

....    
<!--Jquery-->
<script type="text/javascript" src="http://mktietheknot.com/wp-content/themes/Retro/js/copycat/default.js"></script>
</head>

<body <?php body_class(); ?>>

<!-- BEGIN HEADER -->
<div id="header" class="open" style="top: 0px;">
<div class="wrap">
<div id="rsvp">
        <div class="inside">
        <h1 style="font-family: 'Arvo'; display:block;">RSVP</h1>
            <form id="rsvp-form" action="/wp-content/themes/Retro/rsvp-process.php" method="post">
                <div class="another-wrap">
                <div class="input-wrap">
                        <label for="name">Your Name:</label>
                        <input class="text" name="name" id="name" type="text">
                        </div>

                        <div class="input-wrap">
                        <label for="guest-names">Name of Guest(s): <span class="fineprint">optional</span></label>
                        <input class="text" name="guest-names" id="guest-names" type="text">
                        </div>

                        <div class="input-wrap">
                        <label for="number-attending"># Attending:</label>
                        <input class="text" name="number-attending" id="number-attending" type="text">
                        </div>

                        <input class="submit" name="submit" value="Submit" type="submit">
                    </div>
                    <p><span style="color:#000000;">For any question please Email: </span>
            <a href="mailto:test@gmail.com">test@gmail.com</a></p>
        </form>
            <a href="#rsvp" class="rsvp-link">Close</a>
        </div>
</div><!--EndRSVP-->

<div class="section_inn" align="center"><!--NotOriginal-->
    <div id="menu">
        <ul id="nav" class="nav">
            <li class="first">
            <a href="<?php echo home_url(); ?>/#about_section">
            <?php echo retro_filter( get_theme_option('about_label') ); ?></a>
            </li>
            <li class="second">
            <a href="<?php echo home_url(); ?>/#portfolio_section">
            <?php echo retro_filter( get_theme_option('portfolio_label') ); ?></a>
            </li>
            <li class="third">
            <a href="<?php echo home_url(); ?>/#blog_section">
            <?php echo retro_filter( get_theme_option('blog_label') ); ?></a>
            </li>
            <li id="nav-rsvp" class="last">
            <a href="#rsvp">RSVP</a>
            </li>
        </ul>

    <div class="clr"></div>

    <?php if ( get_theme_option('logo') ) : ?>

    <!-- Logo -->
    <div id="top_logo">
    <a href="<?php echo home_url(); ?>/#home_section">
    <img src="<?php echo get_theme_option('logo'); ?>" alt="" /></a>
    </div>

    <?php endif; ?>

    <div class="clr"></div>
    </div><!--EndMenu-->
</div><!--EndSectionInn-->
</div><!--EndWrap-->
</div><!--EndHeader-->

And here is the JQuery itself:

$(document).ready(function() {

jQuery.timer = function(time,func,callback){
var a = {timer:setTimeout(func,time),callback:null}
if(typeof(callback) == 'function'){a.callback = callback;}
return a;
};

jQuery.clearTimer = function(a){
clearTimeout(a.timer);
if(typeof(a.callback) == 'function'){a.callback();};
return this;
};

// RSVP Form Submit
$('#rsvp .submit').click(function(){
  $('#rsvp .submit').hide();
});
$(function(){
  $("#rsvp-form").submit(function(){
  dataString = $("#rsvp-form").serialize();
  $('#rsvp-form .error').remove()
  //var form_html = $("#rsvp-form");
  //console.debug(form_html);
  //$('#rsvp-form').fadeOut();

  $.ajax({
    type: "POST",
    url: "http://mktietheknot.com/wp-content/themes/Retro/rsvp-process.php",
    data: dataString,
    dataType: "json",
    success: function(data) {
      if ( data.status == 'pass' ) {
        $('#rsvp-form').fadeOut(function(){

          $('#rsvp-form').html('<div class="rsvp-received">' +data.response+ '</div>').fadeIn(1000);

        });

        myTimer = $.timer(2500,function(){

          $('#rsvp .rsvp-link').click();

        });

      }
      else {

        $('#rsvp-form').append('<div class="error">' +data.response+ '</div>');
        $('#rsvp .submit').fadeIn('500');
        console.debug(data);

      }
    }
  });

  return false;            

  });
});

  $(function() {
      $('ul.nav a').bind('click',function(event){
      var $anchor = $(this);

      $('html, body').stop().animate({
          scrollTop: $($anchor.attr('href')).offset().top
      }, 1500,'easeInOutExpo');
      /*
      if you don't want to use the easing effects:
      $('html, body').stop().animate({
          scrollTop: $($anchor.attr('href')).offset().top
      }, 1000);
      */
      event.preventDefault();
  });
  });

  $('#nav-rsvp a').unbind();
  $('#nav-rsvp a, .rsvp-link').click(function(){
  if ( $('#header').hasClass('open') ) {
  $('#header').animate({
  top: '-=115'
  }, 750, 'easeInOutCubic');
  $('#header').removeClass('open');
} 
else {
  $('#header').animate({
  top: '+=115'
  }, 750, 'easeInOutCubic');
  $('#header').addClass('open'); 
}
return false;
  });

});
user229044
  • 232,980
  • 40
  • 330
  • 338
  • When i tried to click this link i get few errors. First is js specific "$ is not defined" - are you load jQuery library? @ other errors are 404. – bksi Mar 18 '13 at 22:39
  • I guess I am loading jQuery library at the bottom of the page. I made a few changes that they recommended. Is it still throwing the error? – mikenonymous Mar 18 '13 at 22:59
  • You can check it yourself. Use Chrome and press F12. Click on console and see. Whith mozila use Ctrl+Shift+J to open console. – bksi Mar 18 '13 at 23:00
  • Thanks, I see what you mean now – mikenonymous Mar 18 '13 at 23:07

2 Answers2

1

Wordpress has a no-conflict with jQuery. You need to alter your jQuery to allow for this. Take a look at this:

jQuery Uncaught TypeError: Property '$' of object [object Window] is not a function.

That should at least get you pointed in the right direction. In addition to that, you need to declare the jQuery library before your default.js file. It's currently in your WP Footer.

Community
  • 1
  • 1
user1048676
  • 9,756
  • 26
  • 83
  • 120
  • Gotcha thanks! I moved the default.js file to be below the jQuery library and made the change in the link you sent me to the beginning of my default.js file. Not working yet but I am hopeful haha, I'm going to keep digging into this JQuery stuff. – mikenonymous Mar 18 '13 at 22:56
  • Hmm, for some reason changing the onload from `$(document).ready(function() {` to `jQuery(document).ready(function ($) {` caused my menu anchor tags to stop working. JQuery is very frustrating... – mikenonymous Mar 18 '13 at 23:05
  • You're still getting an error when I inspect the element in Chrome. Uncaught TypeError: Property '$' of object [object Object] is not a function. I'm not sure if you updated it again but I don't see the change that you said you made. – user1048676 Mar 19 '13 at 00:01
  • I had to change it back for a sec, but with the change below it's not throwing the error anymore. The 404's are because I have a couple images not calling the correct path, those are no biggie – mikenonymous Mar 19 '13 at 14:16
  • Yeah that's no big deal. I see that you declare the (function($){ multiple places. You should only need to declare that once at the beginning. I'd also add some debugging. Add an alert or after the $('#nav-rsvp a, .rsvp-link').click(function(){ to make sure that it's actually executing the code after that statement. – user1048676 Mar 19 '13 at 14:36
  • @user2184195 Your issue is now with the !important in your CSS as you mentioned in your question. Since you have the !important you can't overwrite that value with jQuery and it always stays at -115px. When I removed the !important I was able to able to see the RSVP move as you would expect it to. – user1048676 Mar 19 '13 at 14:58
  • Thanks for the tip, now that the RSVP is working I got another question about the menu, but I'll open up another thread because it's not related to the topic of this one – mikenonymous Mar 19 '13 at 15:45
1

First off, grats on the engagement.

Second, you start using jquery stuff in your default.js file, but you dont include jquery until the bottom of the page.

Put jquery at the top, above your default.js file.

edit: wrap the contents of your default.js file with this

(function($){
    //stuff goes here
})(jQuery);

Since the jQuery object is still usable, we create a function around your code and pass jQuery in as $.

castis
  • 8,154
  • 4
  • 41
  • 63
  • Thanks castis, I moved the default.js to be at the bottom of the page because I guess that just how Wordpress formats it's JQuery to be at the bottom. Still getting the hang of this JQuery stuff... slowly but surely thanks for the tip! – mikenonymous Mar 18 '13 at 22:58
  • Thanks castis, that gets rid of the error Chrome is throwing but it's doing the same thing to my menu and not letting the links work. I might just try to find another route if I can't get this working today... thanks for all the help – mikenonymous Mar 19 '13 at 14:17