开发者

First mouse call of JQuery's .show() does not display animation

Hi everyone (first post!). I'm a JQuery and Javascript newbie.

I'm working on the following website: http://www.beautifulinteractions.com/lombo/

I made a custom .js file with my own functions calling JQuery selectors and methods. I call the startup() function from tag and two divs (the menu and and footer) come in in the proper way.

However, the first time (and only the first) I click on a menu element (triggering a .show() call via onclick="javascript:showContent(URL)") the target div gets visibile but does not fade in - it just appears. Every other time I click on a menu item the animation works fine.

What am I doing wrong?

Thank you for your help.


millis = 600;

function startup() {
    $('#hiddenMenu').show(millis, foo());
    $('#footer').show(millis, foo());
    //$(""+"#hiddenContent"+"").show('slow', foo());
}

function showContent(URL) {
    $('#hiddenContent').hide(millis, function() {
                                        $('#hiddenContent').load(URL);
                  开发者_如何学Go                      $('#hiddenContent').show(millis, foo());
     });

}
function hideContent() {
    $('#hiddenContent').hide(millis, foo());
}

function foo() {
    //Do-Nothing
}`


Try replacing your showContent function with the following:

function showContent(URL) {
    $('#hiddenContent').hide(millis, function() {
        $(this).load(URL, function() {
            $(this).show(millis, foo());
        });
    });
}

It could be due to the fact the the $.load call does not complete before the show line is executed. Moving the .show into $.load's callback might do the trick.


You already tried to get a output off the startup() function? by console or alert? so you know if you script is running or not.

and a little tip.. when you using onclick you dont have to use javascript:

so you should do something like this:

onclick="startup();"

should be enough!

EDIT:

make you var millis to this:

var millis = 600;

without var your script will not work in IE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜