0

I am trying to write a piece of code that animates a div when a URL is visited. Here's my code:

if(document.URL.indexOf("index.php") >= 0){

$('#popout-left-menu-container')
.animate(
{
'right':'-3px'
},500
);

};

I have tried this but it doesn't animate?

I have the below piece of text which does work when the #open-menu-button id is clicked.

Any ideas? Many thanks.

$(document).ready(
function(){
    $('#open-menu-button').click(
        function(){
            $('#popout-left-menu-container')
                .animate(
                    {
                        'right':'-3px'
                    },500
                    );

        });

        $('#popoutmenuclose').click(
        function(){
            $('#popout-left-menu-container')
                .animate(
                    {
                        'right':'-1500px'
                    },500
                    );
        });

});
5
  • Can you post relative CSS? Commented Jan 8, 2014 at 16:52
  • 1
    Where is that if located? Put it in a $(document).ready( Commented Jan 8, 2014 at 16:57
  • Where is the code within the page? In the head? Before or after the element you are trying to animate? Is it wrapped in a $(document).ready? Commented Jan 8, 2014 at 16:57
  • It is in the <head>, can you show me the code with the $(document).ready added? Commented Jan 8, 2014 at 17:00
  • It's the same as in your bottom example... $(document).ready(function(){...your code here...}) Commented Jan 8, 2014 at 17:01

1 Answer 1

1

Since the questioner asked to see the implementation discussed in the comments, here it is:

$(document).ready(
function(){
    if(document.URL.indexOf("index.php") >= 0){

    $('#popout-left-menu-container')
    .animate(
    {
    'right':'-3px'
    },500
    );

    };

});

Note that the code is similar but will only fire on document.ready().

Sign up to request clarification or add additional context in comments.

2 Comments

@Steve I didn't really copy paste from the comments, rather I was the first to notice the issue if you look at my comment. I put this answer here at the questioner's request.
Oh my... my biggest apologies... I never saw your comment above. Mea culpa. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.