✔ Как создать потрясающий эффект наведения на карточку с автоплеем видео / How to create awesome card hover effect

Сегодня мы создадим потрясающий эффект с воспроизведением видео при наведении мышки на карточку. Если у вас возникнут какие-либо проблемы при создании этого кода, вы можете скачать исходный код, нажав на кнопку скачать. Кроме того, оставляйте свои вопросы, предложения и отзывы в комментариях ниже.

✔ Как создать потрясающий эффект наведения на карточку с автоплеем видео

HTML КОД:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset='utf-8'/>
	<meta content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1' name='viewport'/>
    <link href='image/favicon.png' rel='icon' type='image/png'/>
    <title>How to create awesome card hover effect -  you have never seen it before</title>
    <!--Google Fonts-->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&family=Roboto:wght@300;400;500;700;900&display=swap" rel="stylesheet">
    <!--Stylesheets-->
    <link rel="stylesheet" href="css/style.css">
</head>

<body>

    <div class="wrap-container">

        <div class="card">
            <div class="container">
                <video src="video/1.mp4" class="video" loop muted></video>
                <div class="content">
                    <h1 class="title">book a tour</h1>
                    <button class="btn">book</button>
                </div>
            </div>
        </div>

    </div>




    <!--Script-->
    <script src="js/script.js"></script>
</body>
</html>
CSS КОД:

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f2f2f2;
    font-family: 'roboto', sans-serif;
}
.wrap-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}
.card {
    width: 300px;
    height: 600px;
    border-radius: 20px;
    padding: 15px;
    transition: .5s;
}
.container {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    transition: .5s;
}
.card:hover,
.card:hover .container {
    box-shadow: -4px -4px 10px #fff,
     4px 4px 20px rgba(0, 0, 0, 0.15),
     inset  4px 4px 20px rgba(0, 0, 0, 0.15),
     inset -4px -4px 10px #fff;
}
.video {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 5%, rgba(0, 0, 0, 0.6) 80%);
    transition: .5s;
    opacity: 0;
    margin-top: 30px;
}
.title {
    font-size: 60px;
    text-align: center;
    text-transform: capitalize;
    font-weight: 300;
    color: #fff;
}
.btn {
    width: 120px;
    height: 50px;
    font-size: 16px;
    background: #fff;
    border-radius: 10px;
    text-transform: capitalize;
    border: none;
    margin: 50px 0;
    cursor: pointer;
}
.btn:hover {
    background: #f2f2f2;
}
.card:hover .content {
    opacity: 1;
    margin-top: 0;
}
JAVASCRIPT КОД:

const card = document.querySelector('.card');
const video = document.querySelector('.video');

card.addEventListener('mouseover', () => {
    video.play();
});

card.addEventListener('mouseleave', () => {
    video.pause();

});


0 Комментарии