Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2011, 11:57 PM   PM User | #1
Ryan.King1809
New to the CF scene

 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Ryan.King1809 is an unknown quantity at this point
jQuery replaceWith

I've set up two buttons to dynamically load in content. However for some reason the content only loads on the first time you click a button. The transition function does receive the correct variables however. The fade0ut animation also doesn't take affect whilst the replaceWith() function is inside the transition function. Can you help me out?

HTML:
Code:
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Javascript Transition Test</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
    </head>

	<body>
    	<div id="navbar">
        	<button name="Page1">Page1</button><button name="Page2">Page2</button>
        </div>
		<div id="content">
        	<p>This is the content for the first page.</p>
		</div>
        <script src="script.js"></script>
	</body>
</html>

Javascript:
Code:
var page1 = "<p>This is the content for the first page.</p>";
var page2 = "<p>This is the content for the second page.</p>";

$("button[name=\"Page1\"]").click(function () {
	transition(page1);
});

$("button[name=\"Page2\"]").click(function () {
	transition(page2);
});

function transition(newPage) {
	$("#content").fadeOut(1000, $("#content").replaceWith(newPage));
	$("#content").fadeIn(1000);
};
Ryan.King1809 is offline   Reply With Quote
Old 11-14-2011, 05:16 AM   PM User | #2
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
I posted a solution in your thread at sitepoint.
webdev1958 is offline   Reply With Quote
Old 11-14-2011, 05:38 AM   PM User | #3
Ryan.King1809
New to the CF scene

 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Ryan.King1809 is an unknown quantity at this point
jquery solution

Code:
var page1 = "<div id=\"content\" style=\"display: none;\"><p>This is the content for the first page.</p></div>";
var page2 = "<div id=\"content\" style=\"display: none;\"><p>This is the content for the second page.</p></div>";

$("button[name=\"Page1\"]").click(function () {
	transition(page1);
});

$("button[name=\"Page2\"]").click(function () {
	transition(page2);
});

function transition(newPage) {
	$("#content").fadeOut(1000, function () {
		$("#content").replaceWith(newPage)
		$("#content").fadeIn(1000);
	});
	
};
Ryan.King1809 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:13 AM.


Advertisement
Log in to turn off these ads.