I am trying to create a simple slider for my website and found this example on jsfiddle: http://jsfiddle.net/AtFeF/79/
From that I created an html file containing all three components from jsfiddle (see below). But when I open this html file in my browser, nothing happens.. Thanks for your advice!
<!DOCTYPE HTML>
<html lang="en">
<head>
<style>
#banner_area img {
display:none;
position: absolute;
top: 0;
left: 0;
}
#banner_area img:first-child {
display:block;
}
#banner_area > img {
width:400px;
height:250px;
}
</style>
<script type="text/javascript">
function cycleImages() {
var images = $('#banner_area img'),
now = images.filter(':visible'),
next = now.next().length ? now.next() : images.first(),
speed = 1000;
now.fadeOut(speed);
next.fadeIn(speed);
}
$(function () {
setInterval(cycleImages, 1400);
});
</script>
</head>
<body>
<div id="banner_area">
<img src="http://www.wallpaperhi.com/thumbnails/detail/20130309/ocean%20beach%20rocks%20australia%201920x1200%20wallpaper_www.wallpaperhi.com_71.jpg" />
<img src="http://www.star.com.au/star-event-centre/PublishingImages/about-sydney-800x500.jpg" />
<img src="http://www.ytravelblog.com/wp-content/uploads/2013/06/Whitsunday-Islands-Queensland-Australia-6.jpg" />
</div>
</body>
</html>
Add jQuery
Enclose the script in
onload
, and add it after the jQuery script tagYou can generally find what you need to add in left sidebar of jsFiddle
It seems that you haven't included jquery file into your html document.
Hence, the code :
wont work. Because $ belongs to jQuery.
So you need to include jquery either by
or download jquery file from jquery.com to your local drive and include with relative path as
You need to include the required javascript files (particularly jQuery).
Add this section to your
<head>
and it should work.or
Import/include jquery file in your code
or the version that you have at fiddle
1.9.1