Hey guys,
I'm not a programmer, but I just spent a little while putting together a basic way to toggle through divs on your landers via JQuery. There are a lot of creative ways to use something like this, which basically lets you show only a bit of content at a time, while staying on the same page. Think surveys, quizzes, etc.
CSS:
Create a div for each section that will be toggled on/off. The first div should be set for display:inline, while the rest would be display:none.
#part1 {
display:inline;
}
#part2 {
display:none;
}
#part3 {
display:none;
}
#part4 {
display:none;
}
#final {
display:none;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
$(function()
{
$("#toggle").toggle(function()
{ // first click
$("#part1").hide();
$("#part2").show();
},
function()
{ // next click
$("#part3").show();
$("#part2").hide();
},
function()
{ // next click
$("#part4").show();
$("#part3").hide();
},
function()
{ // next click
$("#final").show();
$("#part4").hide();
$("#message").hide();
});
});
</script>
<div id="message"> Intro Message: <a id="toggle" href="javascript:void(0);">Click Here</a> </div> <div id="part1"> This is part 1. </div> <div id="part2"> This is part 2. </div> <div id="part3"> This is part 3. </div> <div id="part4"> This is part 4. </div> <div id="final"> This is the final part. </div> </div>
Nice tip. This is great for trying to keep info above the fold (with your call to action), but still gives the user the ability to get more info, without going to another page or below the fold.
nice share! thanks brian
Cool Thanks Brianb. Speaking of jquery - how do you use it to hide a div after about 3 seconds and show another div instead?
^Ha. I've been trying to figure this exact thing out. Not sure...I'm sure someone here can whip that out in 30 seconds...
function()
{ // next click
$("#final").show();
$("#q4").hide();
$("#message").hide();
setTimeout(function() {
$('#final').hide();
}, 1000);
setTimeout(function() {
$('#final2').show();
}, 1000);
awesome stuff!
Solid Brian! Thanks brotha!