本文共 7407 字,大约阅读时间需要 24 分钟。
css 悬停动画
Today we will look into CSS3 Zoom Image animation effect with mouse on hover. With images being the soul of a website, you might have definitely tried your hands on adding some cool hover effects to them.
今天,我们将鼠标悬停在CSS3 Zoom Image动画效果上。 由于图像是网站的灵魂,因此您肯定会尝试向其添加一些很酷的悬停效果。
在本教程中,我写下了一些有用的示例,这些示例使用CSS转换和过渡属性创建完美CSS3缩放图像效果。
Although you may find a large number of jQuery plugins for creating an image zoom effect, CSS3 is perhaps the most recommended one. The reason being its seamless cross-browser compatibility which saves you from the headache associated with addition of lengthy jQuery codes.
尽管您可能会发现大量用于创建图像缩放效果的jQuery插件,但CSS3可能是最推荐的插件。 原因是其无缝的跨浏览器兼容性,这使您免于添加冗长的jQuery代码带来的麻烦。
The three examples that I’ll be looking at in this CSS zoom image tutorial include:
我将在此CSS缩放图像教程中看到的三个示例包括:
transform: scale(2)
and transition: all .3s ease-out
作为第一个示例,我将使用transform: scale(2)
和transition: all .3s ease-out
实现缩放效果 transform: translate(0, 300px);
按照第三个示例,我将使用两个图像来实现缩放效果,其中第二个图像将在鼠标悬停时显示在与CSS父图像的当前位置相关的预定义位置transform: translate(0, 300px);
Let’s start with the first example of css image zoom on hover animation
让我们从悬停动画上CSS图像缩放的第一个示例开始
In this example, I’ve used 2 images to showcase the zoom effect. Here is a detailed explanation of the transition and transform properties of CSS which will be used here:
在此示例中,我使用了2张图像来展示缩放效果。 这是将在此处使用CSS过渡和转换属性的详细说明:
transition: [transition-property] [transition-duration] [transition-timing-function] [transition-delay];
过渡:所有.3s过渡期–此过渡属性将包括以下值:过渡:[过渡属性] [过渡持续时间] [过渡计时功能] [过渡延迟];
As per above, transition-property will have all(comma-separated) or none of the CSS properties, transition-duration will include values which will determine the amount of time that will be consumed in completion of the transition. This will be displayed in seconds and milliseconds.
如上所述,过渡属性将具有全部(逗号分隔)或不具有CSS属性,过渡持续时间将包含将确定完成过渡所花费的时间量的值。 这将以秒和毫秒为单位显示。
In addition to this, the transition-timing-function will be used for specifying the change in speed at which the transition gets modified over the duration(here, I’m referring to the value set for transition-duration). The transition-timing-function property can include the below values:
除此之外,过渡计时功能将用于指定在整个持续时间内修改过渡的速度变化(此处,我指的是为过渡持续时间设置的值)。 transition-timing-function属性可以包含以下值:
Finally, there will be transition-delay which will represent the time delay from when the transition has been triggered.
最后,将存在过渡延迟,该延迟表示从触发过渡开始的时间延迟。
The code associated with this example is shown below:
与该示例关联的代码如下所示:
css3-hover-zoom1.html
css3-hover-zoom1.html
Now, let’s get to know what happens in the second example
现在,让我们了解第二个示例中发生的情况
Here, I’ll be using each of the four images twice. The transition properties used here will include the ones mentioned below:
在这里,我将两次使用四个图像。 此处使用的过渡属性将包括以下提到的属性:
The code associated with this example is shown below:
与该示例关联的代码如下所示:
css3-hover-zoom2.html
css3-hover-zoom2.html
Finally, let’s get to know about the third example of css zoom image animation
最后,让我们了解CSS缩放图像动画的第三个示例
This example is absolutely similar to example no.2 with only a single difference that the resultant image is located at a different position. The transform property used here is:
该示例与示例2绝对相似,仅一个不同之处在于所得图像位于不同位置。 这里使用的transform属性是:
transform: translate(0,300px) : this property is used for shifting the image element from its current location to a new one.
transform:translate(0,300px) :此属性用于将图像元素从其当前位置移动到新位置。
CSS3 Code associated with this example is shown below:
与该示例关联CSS3代码如下所示:
.parentimage:hover + .parentimageLarge{ width:600px; height:600px; transform: translate(0,300px); }
You can visit below URLs for the demo of all three examples.
您可以访问以下URL,获取所有三个示例的演示。
Hope you’d have followed the steps covered in this tutorial and would find them useful enough in achieving the desired zoom effect for your website images.
希望您已按照本教程中介绍的步骤进行操作,并发现它们对实现网站图像所需的缩放效果足够有用。
About the Author: Jason Roiz is qualified outsource web development professional who brings to the table a quantum of learning around . He meets expectations for OSSMedia, a CMS development company giving proficient WordPress, Magento, Drupal and Joomla improvement administrations.
作者简介 :Jason Roiz是合格的外包Web开发专业人员,他将有关的知识带到了桌面。 他满足了CMS开发公司OSSMedia的期望,该公司提供精通WordPress,Magento,Drupal和Joomla改进管理。
翻译自:
css 悬停动画
转载地址:http://fnlzd.baihongyu.com/