Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-16-2011, 09:44 PM   PM User | #1
TheAcidtouch
New to the CF scene

 
Join Date: Dec 2011
Location: Belgium
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
TheAcidtouch is an unknown quantity at this point
Jquery slider without plugin

Hello,

I'm new to jQuery and tought to give myself a small challenge. I wanted to make my own jQuery slider (for div's or images) without any plugins.



When the document is loaded it changes the first div class to 'current'.

This is my div lay-out.
Code:
	
<div id="up"></div>
        <div class="test" class="slide">1</div>
        <div class="test" class="slide">2</div>
        <div class="test" class="slide">3</div>
        <div class="test" class="slide">4</div>
        <div class="test" class="slide">5</div>
    <div id="down"></div>
The following code is executed when I click on a div with id 'up':

Code:
if ($('.slide').is(':first')){
			console.log("error");
		} else {
			$('.current').animate({height:0}, 2000, function() {});
			$('.current').addClass('test');
			$('.current').next('.test').animate({height:300}, 2000, function() {}).addClass('current').removeClass('.test');
			$('.current:last').removeClass('current');
		}
	});
And ofcourse I have similar code for a div with id 'down'.

I think it should work but somehow it does not. When I click a div (up or down) it says, no matter what, 'error'.

The console.log(" ") thing is for firebug.

I hope somebody can show me what is wrong or how I could do the whole thing better. (if even possible)

Thanks,

Jasper
TheAcidtouch is offline   Reply With Quote
Old 12-16-2011, 11:30 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
At first fix your HTML. If you want to assign more than one class to an element, put space separated values in the attribute:
Code:
<div class="test slide">
Also in jQuery you can chain functions. This also increases performance because the DOM doesn’t have to be iterated several times for the same selector.
Code:
$('.current').animate({height:0}, 2000, function() {}).addClass('test').next('.test').animate({height:300}, 2000, function() {}).addClass('current').removeClass('.test');
__________________
Don’t click this link!

Last edited by VIPStephan; 12-16-2011 at 11:33 PM..
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
TheAcidtouch (12-17-2011)
Reply

Bookmarks

Tags
jquery slider plugin

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:32 AM.


Advertisement
Log in to turn off these ads.