Click here to Skip to main content
16,020,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the JQuery slider Cycle2 :- http://jquery.malsup.com/cycle2

, and have 2 different slideshows running on the same page. Everything is working fine but the slideshow div class name is common for both i.e. 'cycle-slideshow'. If I rename it the slideshow won't work.

I need to rename one of the slideshows class as I have a function that add images according to the class name, since they have got both same name the images are added on both slideshows while I only want one to have more images added.



1st slideshow :
HTML
 <div class="cycle-slideshow" 
			data-cycle-fx=scrollHorz
			data-cycle-timeout=1500
		        data-cycle-center-horz=true
			data-cycle-center-vert=true
		>	
		
                <img src="./upload/003.gif">
		<img src="./upload/005.gif">
				
</div>


2nd slide show
HTML
<div class="cycle-slideshow"
		data-cycle-fx="fadeOut"
		data-cycle-pause-on-hover="true"	
		data-cycle-speed="500"
		data-cycle-timeout="7500"
		data-cycle-auto-height="false"					
		>
		
		<img src="./assets/images/title_image1.jpg" >
		<img src="./assets/images/title_image2.jpg">      
		<img src="./assets/images/title_image3.jpg"> 
		<img src="./assets/images/title_image4.jpg">
		<img src="./assets/images/title_image14.jpg"/>
		</div>

                <button  önclick="c()">Add more images</button>


function to add images:-

JavaScript
<script>
var images = [
    '<img src="./assets/images/title_image6.jpg">',
    '<img src="./assets/images/title_image7.jpg">',
    '<img src="./assets/images/title_image8.jpg">'
];

function c() {

    for (var i=0; i < images.length; i++) {
        $('.cycle-slideshow').cycle('add', images[i]);
    }
    $(this).prop('disabled', true)
}
</script>
Posted

1 solution

The problem is that $('.cycle-slideshow') returns an array of jQuery objects in your case.

Try this approach:
HTML
<div class="cycle-slideshow" id="first-slide"...

and than
JavaScript
$('#first-slide').cycle('add', images[i]);
 
Share this answer
 
v2
Comments
datt265 5-Jan-14 10:26am    
ok thats a very good solution, using the id not the class name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900