鼠标悬停时动画_在悬停时创建菜单图像动画

本文介绍了如何在鼠标悬停时创建菜单图像动画,受到Marvin Schwaibold作品的启发,利用GSAP库实现平滑的动画效果,包括图像显示、自定义光标和平滑滚动等功能。
摘要由CSDN通过智能技术生成
鼠标悬停时动画

鼠标悬停时动画

rapid_feat

At Codrops, we love experimenting with playful hover effects. Back in 2018, we explored a set of fun hover animations for links. We called that Image Reveal Hover Effects and it shows how to make images appear with a fancy animation when hovering items of a menu. After seeing the fantastic portfolio of Marvin Schwaibold, I wanted to try this effect again on a larger menu and add that beautiful swing effect when moving the mouse. Using some filters, this can also be made more dramatic.

在Codrops,我们喜欢尝试有趣的悬停效果。 早在2018年,我们就探索了一组有趣的悬停动画以获取链接。 我们将其称为“图像显示悬停效果” ,它展示了如何在悬停菜单项时使图像以精美的动画出现。 看完Marvin Schwaibold出色的作品集之后,我想在更大的菜单上再次尝试这种效果,并在移动鼠标时添加漂亮的摇摆效果。 使用一些过滤器,这也可以变得更加生动。

If you are interested in other similar effect, have a look at these:

如果您对其他类似效果感兴趣,请查看以下内容:

So, today we’ll have a look at how to create this juicy image hover reveal animation:

因此,今天我们来看看如何创建多汁的图像悬停展示动画:

一些标记和样式 (Some Markup and Styling)

We’ll use a nested structure for each menu item because we’ll have several text elements that will appear on page load and hover.

我们将为每个菜单项使用嵌套结构,因为我们将在页面加载和悬停时显示几个文本元素。

But we’ll not go into the text animation on load or the hover effect so what we are interested in here is how we’ll make the image appear for each item. The first thing I do when I want to make a certain effect is to write up the structure that I need using no JavaScript. So let’s take a look at that:

但是我们不会在加载或悬停效果上使用文本动画,因此我们感兴趣的是如何使图像显示在每个项目上。 当我想产生某种效果时,我要做的第一件事就是不用JavaScript来编写所需的结构。 因此,让我们看一下:

<a class="menu__item">
    <span class="menu__item-text">
        <span class="menu__item-textinner">Maria Costa</span>
    </span>
    <span class="menu__item-sub">Style Reset 66 Berlin</span>
    <!-- Markup for the image, inserted with JS -->
    <div class="hover-reveal">
        <div class="hover-reveal__inner">
            <div class="hover-reveal__img" style="background-image: url(img/1.jpg);"></div>
        </div>
    </div>
</a>

In order to construct this markup for the image, we need to save the source somewhere. We’ll use a data attribute on the menu__item, e.g. data-img="img/1.jpg". We’ll go into more detail later on.

为了构造图像的标记,我们需要将源保存在某个地方。 我们将在menu__item上使用data属性,例如data-img="img/1.jpg" 。 稍后我们将详细介绍。

Next, we’ll have some styling for it:

接下来,我们将对其进行一些样式设置:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值