carousel captions following cursor
-
hello! i'm curious if anyone can help out with a line up code i'm sitting on.
i found this super helpful thread from a few years ago that documented having carousel slide captions follow the cursor as you hover over the carousel area. link
the only noticeable issue in this code is when the carousel autoplays, or the user clicks towards the prev/next slide without moving their cursor. the moving caption will not update its text to match the current slide until the cursor moves, due to the nature of the jQuery / function. i have it pasted below for reference. does anyone know what line of code can be adjusted here, so the currentCaption variable is also updated whenever the .is-selected carousel slide changes in the document? and not only when the mouse moves. link to the site - carousel / effect in 1st section
jQuery(".lay-carousel-slide").hover(function(){ var projectNumber = jQuery(".is-selected").data("project"); var currentCaption = jQuery(".single-caption[data-project='"+projectNumber+"']").text(); jQuery(".moving-caption").text(`● ${currentCaption}`); });thank you to anyone looking!
-
jQuery(".lay-carousel-slide").on('hover mouseup', function(){ var projectNumber = jQuery(".is-selected").data("project"); var currentCaption = jQuery(".single-caption[data-project='"+projectNumber+"']").text(); jQuery(".moving-caption").text(`● ${currentCaption}`); });adding mouseup might solve this
does that work?
if not, does this work?:
jQuery(".lay-carousel-slide").on('hover mouseup', function(){ setTimeout(function(){ var projectNumber = jQuery(".is-selected").data("project"); var currentCaption = jQuery(".single-caption[data-project='"+projectNumber+"']").text(); jQuery(".moving-caption").text(`● ${currentCaption}`); }, 0); }); -
thank you armin.
i switched out 'hover' for 'mouseover' in your code, .on('hover') was buggy because the API for it was deprecated i think? 'mouseup' did the trick for when manually switching between slides with mouse clicks! unfortunately, my main issue here is how to listen for when the carousel autoplay advances to the next slide, since this is independent from mouse events. when you wait for the autoplay to switch slides, the caption still stays with the previous slide, until the mouse is moved.
-
<script> window.laytheme.on("newpageshown", function(){ setTimeout(function(){ jQuery(".lay-carousel-wrap").each(function(){ var $carousel = jQuery(this); (function($carousel){ var myswiper = $carousel.data('myswiper'); if(myswiper) { myswiper.on('slideChangeTransitionEnd', function () { console.log('slide changed'); // var ix = myswiper.activeIndex; var $activeSlide = $carousel.find('.is-selected'); console.log($activeSlide) // do your thing }); } })($carousel); }) }, 2000) }); </script> -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login