Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • 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. Connect and find Help
  3. Help plugin - Swap Images on Hover JS

Help plugin - Swap Images on Hover JS

Scheduled Pinned Locked Moved Connect and find Help
2 Posts 2 Posters 341 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.
  • L
    L
    leamarque
    wrote on last edited by leamarque
    #1

    Hi everybody,

    I'm trying to implement some JS into my website to swap images when mouse hover an image (js plugin) "https://www.jqueryscript.net/other/Swap-Images-Cursor-Move-Swinger.html" - I've tried the code with an online editor and it works. See code pen here : https://codepen.io/leamarque/pen/JjKERVq

    I've tried to follow the laytheme JS documentation but I don't seem to get it so I would love some help :)

    Here is what I've wrote into the head section and other screenshots to help you understand :
    Capture d’écran 2020-11-12 à 16.42.50.png
    Capture d’écran 2020-11-12 à 16.43.35.png
    bbebe23b-e33f-4177-9915-d0a8f4357591-image.png
    Here is what the console said:
    Capture d’écran 2020-11-12 à 16.48.28.png

    1 Reply Last reply
    0
    • K
      K
      kalamakumaran
      wrote on last edited by kalamakumaran
      #2

      Here you go!

      Put this in your custom js:

      <script>
          window.laytheme.on("newpageshown", function(layoutObj, type, obj){
          jQuery.fn.swinger = function () {
          return this.each(function () {
              var $container = jQuery(this);
              $container.css({
                  "position": "relative"
              });
              var $images = $container.find("img");
              $images.css({
                  "position": "absolute",
                  "top": "0%",
                  "left": "0%",
                  "width": "100%"
              });
              var $middleImage = jQuery($images[Math.floor($images.length / 2)]);
              $middleImage.css({
                  "z-index": "2",
                  "position": "relative"
              });
              var columnsCount = $images.length;
              $images.each((i, img) => {
                  var left = `${100 / columnsCount * i}%`;
                  var width = `${100 / columnsCount}%`;
                  var $column = jQuery(`<span style="z-index:999;position:absolute;top:0;bottom:0;left:${left};width:${width}"></span>`);
                  jQuery(img).after($column);
                  $column.hover(() => {
                      $images.css({
                          "z-index": "1",
                          "position": "absolute"
                      });
                      jQuery(img).css({
                          "z-index": "2",
                          "position": "relative"
                      });
                  });
              })
          });
      }
      });   
      </script>
      
      <script>
      window.laytheme.on("newpageshown", function(layoutObj, type, obj){
            jQuery(".img-area").swinger();
      });
      </script>
      

      Then add your images via "+More" > +HTML" in your laygridder. Give the row the class "img-area". Should work like this.

      1 Reply Last reply
      1

      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
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      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