Andy
Andy

Reputation: 1432

Loading external txt file into a DIV

http://jsfiddle.net/9BCrs/2/

With respect to the above fiddle how could I use different links in block 1 to load up an external file (txt, HTML) in block 2 before it slides into view? I know that JQuery.load() will be part of the process

$(".block2").load("helloworld.txt");

Upvotes: 1

Views: 143

Answers (1)

Aditya Manohar
Aditya Manohar

Reputation: 2274

This should work - Provide your animate as a complete callback to the .load() function.

$(function() {
    $(".link1").click(function() {
        $.load("url/to/load/from", function() {
            //Insert contents of file wherever
            $(".block1").stop(true, true).animate({ left: -400 }, 200);
            $(".block2").stop(true, true).animate({ left: 25 }, 200);
        });
    });

    $(".link2").click(function() {
        $.load("url/to/load/from", function() {
            //Insert contents of file wherever
            $(".block2").stop(true, true).animate({ left: 450 }, 200);
            $(".block1").stop(true, true).animate({ left: 25 }, 200);
        });
    });
});

Upvotes: 1

Related Questions