Changing slick slider dots style depending on slick-active class? - javascript

For the past couple of days I've been Googling and searching for solutions and have read a ton of manuals, but I'm still struggling somewhere. And yes, I'm a beginner.
So what I want to achieve is to change Slick slider dots depending on the <li class="slick-active"> element class. I've tried many options and if I'm right I need to work with on('beforeChange', function(event, slick, currentSlide, nextSlide).
What it look right now
What I want it to look(1)
What I want it to look(2)
I want that when you load the page, the first slide (the active one having <li class="slick-active">) has an SVG circle with countdown in it while others have a fully colored circle without the countdown. The countdown timer is set the same as the slides' speed (autoplaySpeed: 4000), so when it goes from 00 to 04, the next slide displays.
jQuery(function ($) {
jQuery(document).ready(function () {
// Slider and slider dots
$(".banner-slider").slick({
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
autoplay: true,
autoplaySpeed: 4000,
dots: true,
customPaging : function() {
if ($(".slick-dots > li.slick-active")) {
return '<a class="dot">' + '<div id="countdown"> <div id="countdown-number"></div> <svg> <circle r="18" cx="20" cy="20"></circle> </svg> </div>' + '</a>';
}
else {
return '<a class="dot">' + 'fully colored circle without timer in it' + '</a>';
}
}
});
var countdownNumberEl = document.getElementById('countdown-number');
var countdown = 0;
countdownNumberEl.textContent = countdown;
setInterval(function() {
countdown = ++countdown >= 4 ? 0 : countdown;
countdownNumberEl.textContent = '0' + countdown;
}, 1000); });
All those return statement tags are styled in an .scss file and <div class="banner-slider"></div> has PHP code in it.
If I run the function as it is written now, I get the countdown circles for all my slides. If i use if ($(".slick-dots > li").hasClass(".slick-active")), it returns false in console.log()
So, I'm guessing that I need to use the previously mentioned function on('beforeChange/afterChange', function(event, slick, currentSlide, nextSlide), but I can't figure how to get it to work.

Related

Prevent Auto Slide using Jquery

I am trying to create product slider for devices - but the current jquery i am using is using auto slide - does anyone know how i can achieve this?
I have tried deleting auto: 3000, but i get a white box/image instead of the first image.
I need the first image to slide on then stop to allow people to choose to slide though.
var bullets = $('#thumbnails li.sliderindicator');
var elem = document.getElementById('slider');
window.mySwipe = Swipe(elem, {
startSlide: -1,
auto: 3000,
continuous: true,
disableScroll: false,
stopPropagation: false,
callback: function (pos) {
var i = bullets.length;
while (i--) {
bullets[i].className = 'circle';
}
bullets[pos].className = 'on';
}
});
Thanks
try remove
startSlide: -1,
auto: 3000,
i think if startSlide: -1 it will not display first image look this link .It work ok!

jQuery cycle for text animation on a slideshow

I'm trying to find a way to animate the image title and caption for each slide of a slideshow and sync their animation effects with the ones of the slideshow. i.e. as soon as the slide transition effect has ended, the title goes from right to left and the caption from top to bottom, and when the slide transition effect kicks in, the whole text would fade out at the same time the slide fades out, and let the new slide and text fade in.
I figured out how to make my image title and caption move using .animate ( http://jsfiddle.net/S8F9Y/ ) :
var $j = jQuery.noConflict();
$j(document).ready(function() {
// Get the slideshow options
var $slidespeed = parseInt( meteorslidessettings.meteorslideshowspeed );
var $slidetimeout = parseInt( meteorslidessettings.meteorslideshowduration );
var $slideheight = parseInt( meteorslidessettings.meteorslideshowheight );
var $slidewidth = parseInt( meteorslidessettings.meteorslideshowwidth );
var $slidetransition = meteorslidessettings.meteorslideshowtransition;
var $captionduration = $slidetimeout - ($slidespeed*2);
$j('.meteor-slides h1').delay($slidespeed).animate({left: '30',opacity: 1}, 600, function(){/*Animation complete.*/});
$j('.meteor-slides p').delay($slidespeed + 200).animate({top: '70',opacity: 1}, 600, function(){/*Animation complete.*/});
$j('.meteor-slides h1').delay($captionduration).animate({opacity: 0}, $slidespeed, function(){/*Animation complete.*/});
$j('.meteor-slides p').delay($captionduration - 200).animate({opacity: 0}, $slidespeed, function(){/*Animation complete.*/});
// Setup jQuery Cycle
$j('.meteor-slides').cycle({
cleartypeNoBg: true,
fit: 1,
fx: $slidetransition,
height: $slideheight,
next: '#meteor-next',
pager: '#meteor-buttons',
pagerEvent: 'click',
pause: 1,
prev: '#meteor-prev',
slideExpr: '.mslide',
speed: $slidespeed,
timeout: $slidetimeout,
width: $slidewidth
});
// Setup jQuery TouchWipe
$j('.meteor-slides').touchwipe({
wipeLeft: function() {
$j('.meteor-slides').cycle('next');
},
wipeRight: function() {
$j('.meteor-slides').cycle('prev');
},
preventDefaultEvents: false
});
// Add class to hide and show prev/next nav on hover
$j('.meteor-slides').hover(function () {
$j(this).addClass('navhover');
}, function () {
$j(this).removeClass('navhover');
});
// Set a fixed height for prev/next nav in IE6
if(typeof document.body.style.maxWidth === 'undefined') {
$j('.meteor-nav a').height($slideheight);
}
// Add align class if set in metadata
$j('.meteor-slides').each(function () {
meteormetadata = $j(this).metadata();
if (meteormetadata.align == 'left') {
$j(this).addClass('meteor-left');
} else if (meteormetadata.align == 'right') {
$j(this).addClass('meteor-right');
} else if (meteormetadata.align == 'center') {
$j(this).addClass('meteor-center');
}
});
});
The 1st problem is that there's no cycle so the text animation only
plays once,
the 2nd problem is that text effects are not in sync with slide effects,
the 3rd problem is that there's no slide transition for the first slide so if this is the first slide, the text animation should start right away for h1 and +200ms for p, with no additional delay ($slidespeed).
Thanks in advance,
Kim
Use the callback of each slide instead of trying to sync them by time.
$j('.meteor-slides').cycle({
after: function (currSlideElement) {
// Place all your animations here
// Example:
$j(currSlideElement).find('h1').animate();
// ...
},
cleartypeNoBg: true,
fit: 1,
fx: $slidetransition,
height: $slideheight,
next: '#meteor-next',
pager: '#meteor-buttons',
pagerEvent: 'click',
pause: 1,
prev: '#meteor-prev',
slideExpr: '.mslide',
speed: $slidespeed,
timeout: $slidetimeout,
width: $slidewidth
});
Place any captions and animations where it says // Place all your animations here and they will show after each slide has loaded.
You can also use before depending on what's best suited for your slideshow.
Demo here
Find more about how they are used here.

slideshow + carousel together in jquery

I have implemented a content fade in slide show inside the sliding content panel.
Fade in slide show is in the first li of the sliding panel but the problem is since sliding is moving randomly I am not able to show the slide show.
What I need is, Sliding should wait until the slideshow completes its animation. Once slideshow is done then the next li of the sliding panel should come up.
Here is the code used for that
//Fade in slide show
var quotes = $(".inner_detail div");
var quoteIndex = -1;
function showNextQuote() {
++quoteIndex;
quotes.eq(quoteIndex % quotes.length)
.fadeIn(2000)
.delay(2000)
.fadeOut(2000, showNextQuote);
}
showNextQuote();
//Slider
$('#news-container').vTicker({
speed: 800,
pause: 3000,
animation: 'fade',
mousePause: false,
showItems: 1
});
If you wanna see the slideshow effect, please remove the slider code in js and then you  can see how slideshow works. (Here a fiddle to show only slideshow)
Here is the working DEMO (in this demo the first sliding li has the slideshow div which cant be seen because sliding is moving fast)
Thanks in advance...
You can not achieve this without modifying the plugin. It doesn't maintain a reference to itself, therefore it is simply a bunch of always running functions. Your can either
Modify the plugin and add a reference to itself as seen here
Write your own version
If you decide to go with the first method, the plugin contains a 'isPaused' property, which you can play with to pause the plugin until your animation is over.
I think you can do it if you know the exact no. of elements in the Slideshow from their your can do simple Steps like
1) Wait_For_SlideToFinish = NO.Of.Elements * (fadeIn_Value + delay_Value + fadeOut_value )
2) Now you can Delay slider for xxx no of seconds Wait_For_SlideToFinish before you can initiate slider function.
If i understood your question then this can work for you.
Do you want something like this?
var quotes = $(".inner_detail div");
var quoteIndex = -1;
var fadeIn_time = 2000, delay_time = 2000, fadeOut_time = 2000;
var time_length = quotes.length*(fadeIn_time + delay_time + fadeOut_time);
function showNextQuote() {
++quoteIndex;
quotes.eq(quoteIndex % quotes.length)
.fadeIn(fadeIn_time )
.delay(delay_time )
.fadeOut(fadeOut_time , showNextQuote);
}
showNextQuote();
//Slider
$('#news-container').vTicker({
speed: 800,
pause: time_length,
animation: 'fade',
mousePause: false,
showItems: 1
});
I have found solution for this. I have used callback function to stop the slider until it is done with the action.
//Editorial Slide + Carousel
var isAni = true;
$(window).load(function(){
var quoteIndex = -1;
function showNextQuote(ele,e) {
++quoteIndex;
e.isPaused = true;
if(quoteIndex < ele.length-1){
ele.eq(quoteIndex % ele.length).fadeIn(2000,"swing").delay(2000).fadeOut(2000,"swing", function(){
showNextQuote(ele,e)
});
}else{
ele.eq(quoteIndex % ele.length).fadeIn(2000,"swing").fadeOut(2000,"swing",function(){ele.eq(quoteIndex+1 % ele.length).fadeIn(0);
quoteIndex = -1;e.isPaused = false;});
}
}
//showNextQuote();
//Slider
$('#news-container').vTicker({
speed: 800,
pause: 3000,
animation: 'fade',
mousePause: true,
showItems: 1,
callback : function(ele,e){
var inner = ele.children("li:first").find("div.inner_detail");
if(inner.length !=0){
quoteIndex = -1;
showNextQuote(inner.find("div"),e);
}
}
});
});
PS - Call back function is written in vticker.js but unfortunately i am not able to post that file here.
Thanks all for your responses!!!

jquery cycle slideshow - adding slide prev/next progression (a la scrollHorz) along with custom animation

I am using the jquery cycle plugin with a custom animation. It is working great!
However, I would like the slides to advance to the right or left depending upon the index#, i.e. if the user clicks on link 1 while slide #3 is the active slide the animation will transition out to the right, while if link 4 was clicked on the slide would transition to the left.
The functionality I'm looking for is the same as the scrollHorz/scrollVert transitions.
I understand that what I need is some logic to relate the current frame and the next frame: if (frameclicked on is a higher index than the current slide) {animate to the left} else {animate to the right}
I just don't know where to put it in the code. I hope that makes sense. Any help would be greatly appreciated! Thanks!
Not that it probably helps, but my custom code is below.
$('#s4').before('<div id="nav" class="nav">').cycle({
fx: 'custom',
cssBefore:{
left:1000,
opacity:0,
display:'block'
},
animIn:{
left:0,
opacity:100
},
animOut:{
left:-1000,
opacity:0
},
cssAfter:{
display:'none'
},
speed: 'slow',
easeIn: 'easeInExpo',
easeOut: 'easeInExpo',
next: '.nextnav',
prev: '.previous',
timeout: 0,
containerResize: 1,
fit: 0,
height: 600,
pager: '#slideshow-nav',
pagerAnchorBuilder: function(idx, slide) {
return '#slideshow-nav li:eq(' + (idx) + ')';
}
});
You need to hook into to onPrevNextEvent. They have something called isnext wich gets passed wich basically tells you which direction you are going in.
Example I updated a fiddle I whipped up yesterday for cycle.
http://jsfiddle.net/gx3YE/12/
$(function() {
$('#megaWrapper').cycle({
next : "#next",
prev : "#prev",
timeout : 0,
onPrevNextEvent: function(is,i,el) {
if (is === true) {
alert('slide right');
}
else {
alert('slide left');
}
}
});
});
Isn't what you're describing part of Cycle's core functionality?
Here's how I do it:
$('.slideshow').cycle({
fx: 'scrollHorz',
timeout: 0,
next: '#next',
prev: '#prev'
});

Number behind in picture count (1/10) Jquery Cycle All Plugin

Bit of a newb but just having a small problem using jquery cycle all plugin. I am trying to create an image gallery, with two buttons next and previous which work fine, and with a counter like (1/10) etc. I've got it to work but for some reason the slideshow never counts the first image so therefore is always one image behind.
Somebody pointed out to me it is probably that the array starts at 0 and something else at 1, but I'm not sure where to find this really so just wondered if somebody could help me. Here is the code in the head of my document.
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx:'none',
speed:'fast',
timeout: 0,
next:'#next',
prev:'#prev',
after: onAfter
});
});
function onAfter(curr,next,opts) {
var caption1 = (opts.currSlide +1) + '/' + opts.slideCount;
$('#caption1').html(caption1);
}
</script>
in use with cycle all plugin.
thanks for any help!
so I've changed to this as instructed.
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx:'none',
speed:'fast',
timeout: 0,
next:'#next',
pager: '#caption1',
prev:'#prev',
after: onAfter1
});
});
currentSlide = $("#caption1 a.activeSlide").html()
function onAfter1(curr,next,opts) {
var caption1 = (opts.currSlide +1) + '/' + opts.slideCount;
$('#caption1').html(caption1);
}
</script>
which works fine after the first slide but the first slide randomly says this:
Prev Next (1/111234567891011)
Then when I press next it dissapears, probably my fault but is it something to do with the pre-existing function I have?
if I change to this:
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx:'none',
speed:'fast',
timeout: 0,
next:'#next',
pager: '#caption1',
prev:'#prev',
});
currentSlide = $("#caption1 a.activeSlide").html()
});
</script>
It just says 12345678910 instead of 1 of etc.
Edit:
I have changed code as instructed, see here, http://www.amythornley.co.uk/tests/codeplay.html and:
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx:'fade',
speed:1,
timeout: 0,
pager: '.thepager',
next:'#next',
prev:'#prev',
after: onAfter1
});
});
function onAfter1(curr, next, opts) {
currentSlide = $(".thePager a.activeSlide").html();
if (!currentSlide) currentSlide = "1";
$('.slideCaption').html(currentSlide + '/' + opts.slideCount);
}
</script>
but it still doesn't work even though it works perfectly in your example, getting so annoyed at it! grrr. stupid thing :(
and i know about broken images i havnt uploaded them yet, just a test to see the next/prev problem.
EDIT!
I used my original code simply changing the problem with the 'none' and speed and it appeaars to work fine, maybe this was the problem all along, thanks so much for pointing it out and for all your help even if some of it turned out to be pointless haha
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx:'fade',
speed:1,
timeout: 0,
next:'#next',
prev:'#prev',
after: onAfter1
});
});
function onAfter1(curr,next,opts) {
var caption1 = (opts.currSlide +1) + '/' + opts.slideCount;
$('#caption1').html(caption1);
}
</script>
you could "fiddle" with its native navigation and get the current picture number, for example:
$('.selector').cycle({
fx: 'scrollLeft',
pager: '.selctorOfPagination',
timeout: 15000,
pause: 1,
next: '.selectorOfNext',
prev: '. selectorOfPrevious'
});
check the pager example here: http://jquery.malsup.com/cycle/int2.html
EDIT: check my example here:
http://jsfiddle.net/jackJoe/7DRSv/
You can check which is the current image by obtaining the html of the pager:
currentSlide = $(".thePager a.activeSlide").html()
And then you can use that variable which is correct and you don't need to "guess" which image is current.
EDIT 2:
Check my new example:
http://jsfiddle.net/jackJoe/7DRSv/2/
P.S. the first time the slide animates, the caption doesn't get the active one, so we need to set that variable, check my example.
EDIT 3:
New example with a stopped animation, triggered by the next and previous buttons:
http://jsfiddle.net/jackJoe/7DRSv/3/
One thing I found out is that at your site (BTW the images are broken), when not using anykind of animation (fx: "none") the first active slide is one number behind! which takes us back to your original problem!
You need to use somekind of animation (you can specify the speed in miliseconds);
for an alternative to the "none", use the fx = 'fade' and speed: 1...

Categories

Resources