Jump to content

[Share] Hover Image - Change Video

Recommended Posts

Demo: https://tuanphan3.squarespace.com/hover-image-show-video?noredirect

Pass: abc

Suppose you have 4 images.

You want: when users hover on each image >> Change video on right.

hover-image-change-video-01-min.jpg.ca9efc6840f4307136f8dca5d084a921.jpg

#1. First, add 4 Image Blocks on the Left and 4 Video Blocks on the Right

hover-image-change-video-02-min.jpg.2e9c2b0105490515ea0ec2c89a133b81.jpg

#2. Use this free tool to find the ID of Image and Video Blocks

https://chromewebstore.google.com/detail/squarespace-id-finder/igjamfnifnkmecjidfbdipieoaeghcff

In my example, we will have

  • Google Image: #block-yui_3_17_2_1_1709452007121_25573
  • Microsoft Image: #block-yui_3_17_2_1_1709452007121_26367
  • Apple Image: #block-yui_3_17_2_1_1709452007121_27254
  • Facebook Image: #block-yui_3_17_2_1_1709452007121_28340
  • Video 1: #block-yui_3_17_2_1_1709452007121_29414
  • Video 2: #block-yui_3_17_2_1_1709452007121_30480
  • Video 3: #block-yui_3_17_2_1_1709452007121_31549
  • Video 4: #block-yui_3_17_2_1_1709452007121_32617

hover-image-change-video-03-min.jpg.7bca0b032bb626bcd011df5981682956.jpg

#3. Use this code to Code Injection Footer (or Page Header Code Injection, page where you use Image Blocks, Video Blocks)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  // Apple
  $('#block-yui_3_17_2_1_1709452007121_27254').hover(function(){
    $("#block-yui_3_17_2_1_1709452007121_29414").addClass("show");
    }, function(){
    $('#block-yui_3_17_2_1_1709452007121_29414').removeClass("show");
    }
  );
// Microsoft
 $('#block-yui_3_17_2_1_1709452007121_26367').hover(function(){
    $("#block-yui_3_17_2_1_1709452007121_30480").addClass("show");
    }, function(){
    $('#block-yui_3_17_2_1_1709452007121_30480').removeClass("show");
    }
  );
  // Facebook 
   $('#block-yui_3_17_2_1_1709452007121_28340').hover(function(){
    $("#block-yui_3_17_2_1_1709452007121_31549").addClass("show");
    }, function(){
    $('#block-yui_3_17_2_1_1709452007121_31549').removeClass("show");
    }
  );
 // Google
  $('#block-yui_3_17_2_1_1709452007121_25573').hover(function(){
    $("#block-yui_3_17_2_1_1709452007121_32617").addClass("show");
    }, function(){
    $('#block-yui_3_17_2_1_1709452007121_32617').removeClass("show");
    }
  );
});
</script>
<style>
#block-yui_3_17_2_1_1709452007121_29414, #block-yui_3_17_2_1_1709452007121_30480, #block-yui_3_17_2_1_1709452007121_31549, #block-yui_3_17_2_1_1709452007121_32617 {
  opacity: 0;
  transition: all 0.1s ease;
  }
  .show {
  opacity: 1 !important;
     transition: all 0.1s ease;
  }
</style>

hover-image-change-video-05-min-1.png.eb19f40886028e77a80318f6a2942e5a.png

#4. Explain code

hover-image-change-video-04-min.jpg.c3ce5b52119d8532909b3705c6c60fef.jpg

If you can't make code work, you can comment with your site url, I can help easier

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • Replies 0
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.