views:

39

answers:

3
            <script type="text/javascript">
        $(document).ready(function() {  

            //select all the a tag with name equal to modal
            $('a[rel=popup]').click(function(e) {
                //Cancel the link behavior
                e.preventDefault();

                //Get the A tag
                var id = $(this).attr('href');

                //Get the screen height and width
                var maskHeight = $(document).height();
                var maskWidth = $(window).width();

                //Set heigth and width to mask to fill up the whole screen
                $('#mask').css({'width':maskWidth,'height':maskHeight});

                //transition effect     
                $('#mask').fadeTo("slow",0);    

                //Get the window height and width
                var winH = $(window).height();
                var winW = $(window).width();

                //Set the popup window to center
            $(id).css('top', $(this).height() + $(this).offset().top + 5);

                //transition effect
                $(id).fadeIn(1000); 

            });

            //if close button is clicked
            $('.window .close').click(function (e) {
                //Cancel the link behavior
                e.preventDefault();

                $('#mask').hide();
                $('.window').hide();
            });     

            //if mask is clicked
            $('#mask').click(function () {
                $(this).hide();
                $('.window').hide();
            });         

        });
            </script>
</head><body>
      <div id="subNav">
        <div id="status">

            <a href="#loginPanel" rel="popup">Login</a>
            <div id="loginPanel" class="window">
              <a class="close" href="#close"></a>
              Login Form
            </div> 

            <a href="#registerPanel" rel="popup">Register</a>
            <div id="registerPanel" class="window">
            <a class="close" href=""></a>
              Register Form
            </div>

        </div>
      </div>

script above i put at header.php,

but nothing happend when i click the a tag from url/index.php(require header.php)

but work excellent when i surf url/header.php , how come?

i put the script in head

firefox Error console:

Error: $("a[rel=popup]") is null

Source File: http://localhost/

A: 

Fix your HTML first - fix the /head tag (if this was just copy/paste) - start your body tag after the head - it's likely not finding your divs since they're not in the document.

Andrew
lol.this is not copy/paste from my script , my head tag no error
A: 

you don't fetch id properly

var id = $(this).attr('href');
...
$(id).fadeIn(1000); 

isn't going to work .. maybe try:

var id = this;
...
$(id).fadeIn(1000); 
Scott Evernden
A: 

You probably did something like that

<html>
<head>
<?php require("header.php") ?>
</head>
<body>
</body>

You should put header in body section!

<html>
<head>
</head>
<body>
<?php require("header.php") ?>
</body>
knagode
my head, body all in header.php, index.php is some content only, and close the body in footer.php...is this cause error?and index.php require header.php > some content > footer.php
Try to validate your HTML: http://validator.w3.org/#validate_by_input+with_optionsIs everything OK?
knagode
you are right, something wrong in my html..thanks