Jump to content

Recommended Posts

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

15 hours ago, geglaja said:

Hi, @tuanphan. Thank you! Yes, you are correct; I meant something like that. I would actually need only the hover effect for videos so that they can stay still until the hover.

You can add video with this Code Block

<div class="video-container">
        <video class="video" src="https://www.w3schools.com/tags/movie.mp4" muted loop></video>
</div>
<style>
  .video-container {
    position: relative;
    width: 400px;
    height: 300px;
    padding: 40px;
    margin: 20px;
    overflow: hidden;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: box-shadow 0.3s ease-in-out;
}

.video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
    transform: scale(1);
}

.video-container:hover {
    box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.6);
}

.video-container:hover .video {
    opacity: 1;
    transform: scale(1.05);
}

</style>
<script>
  const video = document.querySelector('.video');

video.addEventListener('mouseover', function () {
    this.play();
});

video.addEventListener('mouseout', function () {
    this.pause();
    this.currentTime = 0;
});

</script>

 

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
3 hours ago, tuanphan said:

You can add video with this Code Block

<div class="video-container">
        <video class="video" src="https://www.w3schools.com/tags/movie.mp4" muted loop></video>
</div>
<style>
  .video-container {
    position: relative;
    width: 400px;
    height: 300px;
    padding: 40px;
    margin: 20px;
    overflow: hidden;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: box-shadow 0.3s ease-in-out;
}

.video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
    transition: opacity 0.3s, transform 0.3s;
    transform: scale(1);
}

.video-container:hover {
    box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.6);
}

.video-container:hover .video {
    opacity: 1;
    transform: scale(1.05);
}

</style>
<script>
  const video = document.querySelector('.video');

video.addEventListener('mouseover', function () {
    this.play();
});

video.addEventListener('mouseout', function () {
    this.pause();
    this.currentTime = 0;
});

</script>

 

Hello @tuanphan Thanks!

Do you have any advice for making video autoplay hovers work in Safari like they do in Chrome? Thank you for your help.

Link to comment
On 9/9/2023 at 8:05 PM, geglaja said:

Hello @tuanphan Thanks!

Do you have any advice for making video autoplay hovers work in Safari like they do in Chrome? Thank you for your help.

You mean this code doesn't work on Safari? I will check it again

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

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

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.