Home › Forums › JavaScript › Add class Jquery
- This topic is empty.
-
AuthorPosts
-
April 7, 2012 at 2:29 pm #37540
elcape16
MemberHello I’m trying to do a slider and have jquery add a class on content out side that slider, Is it possible? I’m not good at all with Jquey.
Something like this!
slider here
Slider 1 - Color Orange
Slider 2 - Color Blue
Content Hereadd class orange when Slide 1 is current or add class blue when Slide 2 is current
Thanks is advance!!
Alex
April 7, 2012 at 3:59 pm #100793elcape16
MemberYes Anything slider, but my question is how to add a class to another element outside the slider itself
April 8, 2012 at 1:17 am #100809Mottie
MemberYou can use the built in callbacks AnythingSlider provides (demo):
jQuery(function($){
var $box = $('.colorbox'),
// class to add: slide 1 = blue, slide 2 = orange, etc
colors = [ 'blue', 'orange', 'green' ],
changeBox = function(slider){
$box
.removeClass( colors.join(' ') )
.addClass( colors[slider.currentPage-1] || '' )
};
$('#slider').anythingSlider({
// Callback when the plugin finished initializing
onInitialized: function(e, slider) {
changeBox(slider);
},
// Callback when slide completes - no event variable!
onSlideComplete: function(slider) {
changeBox(slider);
}
});
});April 8, 2012 at 10:46 am #100844elcape16
MemberApril 8, 2012 at 11:00 am #100845elcape16
MemberMottie, Thanks….
That’s exactly what I need can I do to more than one element, sorry my Jquery skills are almost none :S
April 8, 2012 at 4:24 pm #100865Mottie
MemberJust change this line:
$box = $('.colorbox'),
to point to those box title class names; i.e., it doesn’t need to be unique since we’re using classes.
April 8, 2012 at 4:53 pm #100868elcape16
MemberThanks I’m working on it!! Thanks A Lot
May 23, 2012 at 2:21 pm #103343semismurf
MemberHey mottie. What if i have an id in the nav that i want to add a class “active” to based on which slide i’m on.
id=”nav1″ class=”menu active” <-- active slide id=”nav2″ class=”menu”
id=”nav3″ class=”menu”
id=”nav4″ class=”menu”id=”nav1″ class=”menu”
id=”nav2″ class=”menu active” <-- active slide after hitting next id=”nav3″ class=”menu”
id=”nav4″ class=”menu”what would that look like?
May 24, 2012 at 10:24 pm #103460 -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.