June 11, 201016 yr Hi folks, just wondering if any of the javascript wiz kids have a code for replacing one div of text with another when their corresponding links are clicked? Thanks if you can help!
June 11, 201016 yr Sounds like you want to do something similar to what any generic jQuery slider does? Here's a commonly used one: http://css-tricks.com/anythingslider-jquery-plugin/
June 11, 201016 yr jQuery is Javascript? This would be the inefficient and horrible looking way of doing it; search engines won't like it though: <div id="container">This is the homepage<br />...</div> <a href="#" title="Home" onclick="show('home');return false">Home</a> <a href="#" title="About" onclick="show('about');return false">About</a> <a href="#" title="Contact" onclick="show('contact');return false">Contact</a> Then put this in your head and add items/code as necessary: <script type="text/javascript"> function show(page) { var html = ""; switch(page) { case "home": html = "This is the homepage<br />...";break; case "about": html = "This is the about page<br />...";break; case "contact": html = "This is the contact page<br />...";break; } document.getElementById('container').innerHTML = html; } </script>
June 13, 201016 yr Author That's great andyl. It worked a treat! Thanks so much! Do you have any idea how I can make each of the cases 'fade in' so that it has a nice stylish feel? I appreciate this!
June 13, 201016 yr I think what you're looking for is called 'tabbed content'. This a good article to get you started: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
June 13, 201016 yr Author Is there a way I can do it using the code already given to me? Don't want to have to delete everything I've just done!
June 13, 201016 yr Do you have any idea how I can make each of the cases 'fade in' so that it has a nice stylish feel? Well, you have to use jQuery or Flash for that - and you said you didn't want jQuery so I'm afraid not! I'll post a jQuery script tomorrow which will do the same thing - in a nice fadey fashion.
June 14, 201016 yr Author I am not that great with Javascript/Jquery so need a more relevant example lee grant. Thanks anyway tho. Looking forward to your suggestion andyl. Your last suggestion was great! Thanks guys!
June 14, 201016 yr Well, you have to use jQuery or Flash for that - and you said you didn't want jQuery so I'm afraid not! I'll post a jQuery script tomorrow which will do the same thing - in a nice fadey fashion. I just want to point out that jQuery, being JavaScript-based, proves that neither jQuery nor Flash is essential for that effect. A fade animation is nothing but a looping setTimeout(). A good example script is on Switch on the Code which shows just how simple it can be
June 14, 201016 yr For sheer simplicity's sake, could something like this not just be used? http://www.jsfiddle.net/LSyX4/ It would also depend on how many divs you wish to toggle in order to determine the best solution. If it's just two divs, it could be achieved really easily with jquery's toggle function.
June 14, 201016 yr Author I have 3 paragraphs of text. One should only be visible at a time. However I will be adding more in the future so it should be simple just to add further paragraphs when needed. I suppose it would make things a lot clearer if I just showed you the page... http://www.aesthetemedia.co.uk/info.html As you can see andyl's suggestion is perfect. I just want it to fade so that it looks more stylish. Appreciate your thoughts guys!
June 16, 201016 yr Sorry about the delay - had some trouble with an email server which pretty much took out 2 days of my life. Here's your nice effects version: Put this in the <head> tags: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ var speed = 500; // The lower this number, the faster. Time in milliseconds. var animating = false; $("a.nav").click(function(){ if ((!animating) && $("#"+$(this).attr("rel")).is(":hidden")) { animating = true; var requestedDiv = "#"+$(this).attr("rel"); $("#container").children("div").each(function(){$(this).fadeOut(speed/2)}); $("#container").animate({height: $(requestedDiv).height()}, speed); $(requestedDiv).delay(speed/1.5).fadeIn(speed); setTimeout(function(){animating = false}, speed*2); } return false; }); }); </script> <style type="text/css"> #container div{display:none} #container div#homepage{display:block} </style> Then this is your HTML: <div id="container"> <div id="homepage">This is the homepage...<br />Add more content as you wish, you can use any HMTL/CSS </div> <div id="about">This is the about page...<br />Add more content as you wish...</div> <div id="contact"> <form action="" method="post"> <label>Name</label><input type="text" name="name" /><br /> <label>Email</label><input type="text" name="email" /><br /> <label>Message</label><textarea name="message"></textarea><br /> <p>Contact page...</p> </form> </div> </div> <a href="#" class="nav" title="Home" rel="homepage">Home</a> <a href="#" class="nav" title="About" rel="about">About</a> <a href="#" class="nav" title="Contact" rel="contact">Contact</a> To add more 'pages' <div id="newPage">Blah...</div> <!-- Put this inside <div id="container"> --> <a href="#" class="nav" title="New Page Title" rel="newPage">New Page Link</a> <!-- Put this with your navigation --> Tested on Chrome, Safari and Firefox - briefly.
December 8, 201213 yr wow where are the mods? this thread is being flooded with spam posts [sorted - Wickham] Edited December 10, 201213 yr by Wickham
January 12, 201313 yr I actually read all of this and came across this little gem: Generally, you might have thirty days to modify your brain Gotta love google translate!
Create an account or sign in to comment