Jump to content

help with slider


CyberShot

Recommended Posts

i need help with my code. I made a very very simple slider that does work. Here is the code

 

$("#headerBottom p").hide();
$("#logo").hide();

$("#headerBottom p:eq(4)").show();
$("#content span").hide();				 
    $("#content span:eq(0)").show();

$("#topLogo").click(function(){
	$("#content span").hide();
	$("#headerBottom p").hide();
	$("#content span:eq(0)").show();
	$("#headerBottom p:eq(4)").show();
 });

   $("#aboutPage").click(function(){
	if($("#content span:eq(1)").is(':visible'))
	{
		$("#aboutPage").show();
	} else {
	$("#headerBottom p:eq(4)").hide();
	$("#content span").slideUp();
	$("#content span:eq(1)").slideDown(); 
	$("#headerBottom p").hide();
	$("#headerBottom p:eq(0)").show();
	}
 });
   
   $("#workPage").click(function(){
	if($("#content span:eq(2)").is(':visible'))
	{
		$("#workPage").show();
	} else {
	$("#content span").slideUp();
	$("#content span:eq(2)").slideDown();
	$("#headerBottom p").hide();
	$("#headerBottom p:eq(1)").show();
	}
 });

$("#socialPage").click(function(){
	if($("#content span:eq(3)").is(':visible'))
	{
		$("#aboutPage").show();
	} else {
	$("#content span").slideUp();
	$("#content span:eq(3)").slideDown();
	$("#headerBottom p").hide();
	$("#headerBottom p:eq(2)").show();
	}
 });

$("#contactPage").click(function(){
	if($("#content span:eq(4)").is(':visible'))
	{
		$("#contactPage").show();
	} else {

	$("#content span").slideUp();
	$("#content span:eq(4)").slideDown();
	$("#headerBottom p").hide();
	$("#headerBottom p:eq(3)").show();
	}
 });
});


my issue is that I am using the span tag as a hook. To say in the code...Find all span tags and hide their content. But the problem is that the span tag is an inline element and I am running into validation problems using a block element inside an inline element. So I need to re work this code. I thought instead. Maybe I could put my 4 divs into an array and call them that way or seperately. something like

var contentDiv = array [#about, #work, #social, #contact];

so then in my jquery above, instead of saying ("#content span").slideUp(); 

I could do ("contentDiv").slideUp();
("contentDiv:eq(1)").slideDown();

but not sure how to make the array. can you help

Link to comment
https://forums.phpfreaks.com/topic/183877-help-with-slider/
Share on other sites

I am getting a syntax error, this is my test code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript">
$(docuemtn).ready(function(){
var contentDiv = array ['about', 'work', 'social', 'contact'];

$.each(contentDiv. function(){  
$('#'+this+':eq(0)).hide();  
$('#'+this+':eq(1)).slideDown();
});

</script>

<style type="text/css">
#about {
width: 100px; height: 100px;
}

#work {
width: 100px; height: 100px;
}
#social {
width: 100px; height: 100px;
}
#contact {
width: 100px; height: 100px;
}
</style>
</head>

<body>

<div id="about">
about
</div>

<div id="work">
work
</div>

<div id="social">
social
</div>

<div id="contact">
contact
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/183877-help-with-slider/#findComment-970697
Share on other sites

ok, fixed that and also noticed that the funciton wasn't closed with the }); but still something is wrong

 

$(docuemtn).ready(function(){
var contentDiv = array ['about', 'work', 'social', 'contact'];

$.each(contentDiv .function(){  
$('#'+this+':eq(0)').hide();  
$('#'+this+':eq(1)').slideDown();
						});
					   });

Link to comment
https://forums.phpfreaks.com/topic/183877-help-with-slider/#findComment-970700
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.