Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. carousel captions following cursor

carousel captions following cursor

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 123 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spiralglue
    wrote on last edited by spiralglue
    #1

    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!

    1 Reply Last reply
    0
    • arminunruhA Offline
      arminunruhA Offline
      arminunruh
      Global Moderator
      wrote on last edited by
      #2
      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);
              });
      
      1 Reply Last reply
      1
      • S Offline
        S Offline
        spiralglue
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • arminunruhA Offline
          arminunruhA Offline
          arminunruh
          Global Moderator
          wrote on last edited by
          #4
          <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>
          
          1 Reply Last reply
          0
          • arminunruhA Offline
            arminunruhA Offline
            arminunruh
            Global Moderator
            wrote on last edited by
            #5

            maybe other events will be better for u / good reads:

            https://swiperjs.com/swiper-api#events

            https://stackoverflow.com/questions/32945099/how-to-detect-current-slide-in-swiper-js

            https://stackoverflow.com/questions/592396/what-is-the-purpose-of-a-self-executing-function-in-javascript

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            I also code custom websites or custom Lay features.
            šŸ’æ Email me here: šŸ’æ
            info@laytheme.com

            Before you post:
            1. When using a WordPress Cache plugin, disable it or clear your cache.
            2. Update Lay Theme and all Lay Theme Addons
            3. Disable all Plugins
            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

            This often solves issues you might run into

            When you post:
            1. Post a link to where the problem is
            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
            Online Users
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search