One for the web fol...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] One for the web folk, can't get my slider to work

8 Posts
4 Users
0 Reactions
77 Views
Posts: 0
Free Member
Topic starter
 

Here goes. I'm trying to build a slider using Jquery. Now I'm following a tutorial and I've built this to the letter using my own pics, but for the life of me I can't get the first pic to load up. I've reduced the size of the file considerably but it just keeps hanging on my little loading icon.

Any suggestions on what else I should be looking at?

We are talking very simple code, nothing flash to pardon the pun (i'll get my coat)


 
Posted : 03/12/2012 11:50 am
Posts: 0
Free Member
 

Any chance of seeing to code ?

Are your image paths ok ?


 
Posted : 03/12/2012 12:17 pm
Posts: 0
Free Member
Topic starter
 

Go mental:

[b]<!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>Slider</title>

<style type="text/css">

.slider{
width:800px;
height: 350px;
overflow: hidden;
margin:30px auto;
background-image:url(slider/load.gif);
background-repeat:no-repeat;
background-position:center;
}
.shadow{
background-image:url(slider/shadow.png);
background-repeat:no-repeat;
background-position:top;
width:864px;
height:144px;
margin:-60px auto;
}
.slider img{
width:800px;
height:350px;
display:none;
}

</style>

<script type="text/javascript" src="slider/jquery-1.8.3.js"></script>
<script type="text/javascript" src="slider/jquery-ui-1.9.2.custom.js"></script>
<script type="text/javascript">
function Slider(){
$(".slider#1").show("fade",500);
$(".slider#1").delay(5500).hide("slide",{direction:"left"},500);

var sc =$(".slider img").size();
var count = 2;

setInterval(function(){
$(".slider#"+count).show("slide",{direction:"right"}, 500);
$(".slider#"+count).delay(5500).hide("slide",{direction:"left"},500);

if(count==sc){
count=1;
}else{
count=count+1;}},6500);

}

</script>

</head>

<body onload="Slider()";>

<div class="slider">
<img id="1" src="images/computer.jpg" border="0" alt="computer"/>
<img id="2" src="images/design.jpg" border="0" alt="design"/>

</div>
<div class="shadow"></div>
</body>
</html>[/b]


 
Posted : 03/12/2012 12:35 pm
Posts: 0
Free Member
Topic starter
 

The image locations are sound


 
Posted : 03/12/2012 12:38 pm
Posts: 3544
Free Member
 

Not sure if id can be just a numeric - try 'pic1' instead of just '1'. That might be it.

And the jQuery selector is over the top - each ID is unique (or should be!!!) so instead of '.slider#1' you can just use '#1' (or rather '#pic1').


 
Posted : 03/12/2012 1:06 pm
Posts: 3544
Free Member
 

Oh, and I think I remember a strange buglet in Jquery - instead of

$(".slider#"+count).show("slide",{direction:"right"}, 500);

set a variable up first:-

var mySlider = ".slider#" + count;
$(mySlider).show("slide",{direction:"right"}, 500);


 
Posted : 03/12/2012 1:08 pm
Posts: 0
Free Member
 

one other thing, there shouldn't be any need to have any JS in the HTML so remove the...

onload="Slider()";
and instead use a...
$(document).ready(function() {
Slider();
});

infact its probably even better to use
$(window).load(function() {
Slider();
});

as this wont start until the images have finished downloading


 
Posted : 03/12/2012 1:22 pm
Posts: 0
Free Member
Topic starter
 

excellent, thank you, that all worked except now my second image wont load. Still further than I was because the first one will, just got to figure out why the second won't load (then obviously I can expand the number of images)

Do I need to repeat the code?

(I'm sure I could probably just download a plugin, but that feels like cheating)


 
Posted : 03/12/2012 1:27 pm
Posts: 0
Free Member
 

haven't tested it, but it could well be because the count variable is in a different scope to the set interval function when it eventually calls itself, try alert()'ing out the count inside the interval fn

also, the using Id's will become a bit clunky when you start to scale it up, it's much cleaner to use classes, I found this approach was a really good starting place when I wrote my own plugin ... http://jonraasch.com/blog/a-simple-jquery-slideshow


 
Posted : 03/12/2012 2:41 pm

6 DAYS LEFT
We are currently at 95% of our target!