css鼠标滑过图标显示

View demo 查看演示Download Source 下载源

Today I want to show you, how to create an Apple-style navigation menu with a twist. Although “fancy” and “Apple-style” don’t really go together, I thought that it’s time for something different.

今天,我想向您展示如何创建一个苹果风格的导航菜单。 尽管“花式”和“苹果风格”并没有真正融为一体,但我认为该是时候有所不同了。

This menu looks very similar to the Apple-style navigation but it reveals some icons when hovering over it. The icons slide out from the top and when the mouse leaves the link, the icon slides back under the link element. This creates a neat “card-shuffle” effect.

该菜单看起来与Apple样式的导航非常相似,但是将鼠标悬停在菜单上时会显示一些图标。 图标从顶部滑出,当鼠标离开链接时,图标在链接元素下方向后滑动。 这会产生整洁的“洗牌”效果。

The icons used in this tutorial can be found on DryIcons.com. I am not allowed to redistribute the icons under the free license, so I did not include them in the downloadable ZIP file. But you can easily find them here. I did not rename them for the tutorial so that you can easily recreate the navigation without changing the names or the stylesheet.

本教程中使用的图标可以在DryIcons.com上找到。 我不允许在免费许可证下重新分发图标,因此我没有将它们包含在可下载的ZIP文件中。 但是您可以在这里轻松找到它们。 我没有为教程重命名它们,因此您可以轻松地重新创建导航,而无需更改名称或样式表。

Ok, let’s get started!

好的,让我们开始吧!

1. HTML (1. The HTML)

The markup just consists of a div with an unordered list inside. The list elements contain a span for the icon and the link element:

标记仅包含一个div,其中包含一个无序列表。 列表元素包含图标和链接元素的范围:

<div class="navigation">
<ul class="menu" id="menu">
<li><span class="ipod"></span><a href="" class="first">Players</a></li>
<li><span class="video_camera"></span><a href="">Cameras</a></li>
<li><span class="television"></span><a href="">TVs</a></li>
<li><span class="monitor"></span><a href="">Screens</a></li>
<li><span class="toolbox"></span><a href="">Tools</a></li>
<li><span class="telephone"></span><a href="">Phones</a></li>
<li><span class="print"></span><a href="" class="last">Printers</a></li>
</ul>
</div>

2. CSS (2. The CSS)

The style of the navigation container and the unordered list will be the following:

导航容器的样式和无序列表如下:

.navigation{
position:relative;
margin:0 auto;
width:915px;
}
ul.menu{
list-style:none;
font-family:"Verdana",sans-serif;
border-top:1px solid #bebebe;
margin:0px;
padding:0px;
float:left;
}
ul.menu li{
float:left;
}

Since we are making the list float, we will need some relative wrapper for the icons. You see, the icons which will be the background-images of the spans in our list, will have absolute positioning. That comes handy when you need to define a z-index, i.e. saying that some element is on top or under another one. Since we want the icons to appear on top and then dissapear under the link element, we will have to deal with z-indeces. And absolute positioning of elements in a relative container will makes things easier.

由于我们使列表浮动,因此我们需要一些相对的包装图标。 您会看到,这些图标(将成为我们列表中跨度的背景图像)将具有绝对的位置。 当您需要定义z-index时(即说某个元素在另一个元素的上方或下方),这很方便。 由于我们希望图标显示在顶部,然后在link元素下消失,因此我们必须处理z坐标。 元素在相对容器中的绝对定位将使事情变得容易。

Now, let’s define the style for the link elements:

现在,让我们定义链接元素的样式:

ul.menu li a{
text-decoration:none;
background:#7E7E7E url(../images/bgMenu.png) repeat-x top left;
padding:15px 0px;
width:128px;
color:#333333;
float:left;
text-align:center;
border-right:1px solid #a1a1a1;
border-left:1px solid #e8e8e8;
font-weight:bold;
font-size:13px;
-moz-box-shadow: 0 1px 3px #555;
-webkit-box-shadow: 0 1px 3px #555;
text-shadow: 0 1px 1px #fff;
}

We want to give the link elements a fixed width and some background gradient. The borders will create a nice inset effect.

我们想给链接元素一个固定的宽度和一些背景渐变。 边框会产生不错的插图效果。

The next hover class will be applied using jQuery, since the :hover pseudo class creates an unwanted effect: When the icon slides out it covers the link for a few milliseconds, making the hover style dissapear in that time. That is perceived as a flicker and we will avoid that by defining a class that we will simply add with jQuery when we do the icon slide out effect:

下一个悬停类将使用jQuery来应用,因为:hover伪类会产生有害的效果:当图标滑出时,它会覆盖链接几毫秒,从而使悬停样式在那时消失。 这被认为是一种闪烁,我们将通过定义一个类来避免这种情况,该类在执行图标滑出效果时将简单地添加到jQuery中:

ul.menu li a.hover{
background-image:none;
color:#fff;
text-shadow: 0 -1px 1px #000;
}

The first and last link element should have a rounded border on the respective side, so we define two classes for those:

第一个和最后一个链接元素应在各自的侧面上具有圆角边框,因此我们为它们定义了两个类:

ul.menu li a.first{
-moz-border-radius:0px 0px 0px 10px;
-webkit-border-bottom-left-radius: 10px;
border-left:none;
}
ul.menu li a.last{
-moz-border-radius:0px 0px 10px 0px;
-webkit-border-bottom-right-radius: 10px;
}

The common style for all the icon spans will be the following:

所有图标范围的通用样式如下:

ul.menu li span{
width:64px;
height:64px;
background-repeat:no-repeat;
background-color:transparent;
position:absolute;
z-index:-1;
top:80px;
cursor:pointer;
}

The single styles for the specific icons will contain the background-image and the x-position:

特定图标的单一样式将包含背景图像和x位置:

ul.menu li span.ipod{
background-image:url(../icons/ipod.png);
left:33px; /*128/2 - 32(half of icon) +1 of border*/
}
ul.menu li span.video_camera{
background-image:url(../icons/video_camera.png);
left:163px; /* plus 128 + 2px of border*/
}
ul.menu li span.television{
background-image:url(../icons/television.png);
left:293px;
}
ul.menu li span.monitor{
background-image:url(../icons/monitor.png);
left:423px;
}
ul.menu li span.toolbox{
background-image:url(../icons/toolbox.png);
left:553px;
}
ul.menu li span.telephone{
background-image:url(../icons/telephone.png);
left:683px;
}
ul.menu li span.print{
background-image:url(../icons/print.png);
left:813px;
}

As you can see, we are positioning the icons in such a way, that they are centered inside of the list element. The top position is 80px initially since we want to show them to the user when the page get’s loaded. Then we will hide them in a stair-like fashion to create an awesome effect!

如您所见,我们将图标放置在列表元素内部居中的位置。 最初,最高位置是80px,因为我们希望在加载页面时向用户显示它们。 然后,我们将它们以楼梯状的方式隐藏起来,以产生令人赞叹的效果!

3. JavaScript (3. The JavaScript)

First, we want to create the effect of the icons dissapearing in a stair-like fashion and then we will define the hover function for the list elements:

首先,我们要以阶梯状的方式创建消失的图标的效果,然后为列表元素定义悬停功能:

$(function() {
var d=1000;
$('#menu span').each(function(){
$(this).stop().animate({
'top':'-17px'
},d+=250);
});$('#menu > li').hover(
function () {
var $this = $(this);
$('a',$this).addClass('hover');
$('span',$this).stop().animate({
'top':'40px'
},300).css({
'zIndex':'10'
});
},
function () {
var $this = $(this);
$('a',$this).removeClass('hover');
$('span',$this).stop().animate({
'top':'-17px'
},800).css({
'zIndex':'-1'
});
}
);
});

When hovering, we add the class “hover” to the link element, make the icon appear from the top, and increase the z-Index, so that the icon stays on top of the link. When the mouse goes out, we do exactly the opposite, which creates the effect that the icon dissapears behind the link element. For that we will allow more time (800 milliseconds) because it’s such a fun effect that the user might want to enjoy a little bit!

悬停时,我们将“悬停”类添加到链接元素,使图标从顶部显示,并增加z-Index,以便图标停留在链接的顶部。 当鼠标移出时,我们执行相反的操作,从而产生图标消失在link元素后面的效果。 为此,我们将允许更多的时间(800毫秒),因为这是一种有趣的效果,用户可能希望尽情享受!

And that’s all! I hope you like and enjoy it!

就这样! 希望您喜欢并喜欢它!

cisco training to learn jQuery and other useful web applications. Learn how to create fancy apple style slid out navigation in jquery using cisco培训以学习jQuery和其他有用的Web应用程序。 使用ccvp self study guide and ccvp自学指南和ccda video tutorials.ccda视频教程,了解如何在jquery中创建精美的苹果风格滑出式导航。

翻译自: https://tympanus.net/codrops/2010/01/17/css-and-jquery-tutorial-fancy-apple-style-icon-slide-out-navigation/

css鼠标滑过图标显示

css鼠标滑过图标显示_CSS和jQuery教程:苹果风格的花式图标滑出导航相关推荐

  1. 计算机右下角图标显示桌面快捷方式,Win7系统下让常用软件图标显示在电脑右下角的方法【图】...

    Win7系统下让常用软件图标显示在电脑右下角的方法分享给大家,大家会发现,一些新安装的win7系统电脑桌面右下角可能没有你习惯的软件图标,比如:腾讯QQ.酷狗等.因为Win7系统希望界面显示得更加简洁 ...

  2. linux 图标显示 异常,在Ubuntu 18.04系统中VSCode图标显示异常的解决方法

    以下介绍在Ubuntu 18.04系统中VSCode图标显示异常的解决方法,同时附上在Ubuntu 18.04系统中安装Anaconda3-5.3.0方法.VSCode是一款全平台开发的编辑器,它具有 ...

  3. 关于PPT嵌入对象文件图标显示为文字的方法(比如将系统图标换成文字)

    在做课件时,往往需要将其他文件链接到当前PPT中,比如数学中的解题步骤做在另外一个文件中,点击"解一""解二"时才显示该解题过程. 如图 在编辑好解题过程文件后 ...

  4. 卸载WPS后安装office,office文档图标显示异常的解决方法

    参考:https://blog.csdn.net/loveyuexibo/article/details/82049867 文档图标显示为全白,或者像可执行程序的图标等 首先找到自己的office安装 ...

  5. 计算机桌面上常见的图标有,win10白图标修复的方法是什么_win10电脑桌面图标显示白色方块的解决方法-系统城...

    最近有朋友问小编win10白图标修复的方法是什么,对于win10桌面图标有小白纸的问题,应该有不少朋友遇到过.有很多朋友发现win10桌面部分图标变白,不知道是怎么回事,那么当我们的win10系统出现 ...

  6. esp8266 OLED气象图标显示的来龙去脉

    esp8266 OLED气象图标显示的来龙去脉 通过esp8266+128x64OLED气象站的气象图标显示,在之前像迷一样困惑我好久,这东西是怎么显示出来的,看遍了代码,也没看到出处,今天总算了结了 ...

  7. win7系统图标太大的缩小教程

    win7系统图标太大怎么办?图标大小直接影响了系统的第一观感,一个大小合适的图标能够让用户在使用时拥有更舒服的操作体验,也能在一定程度上避免视力和精神的消耗.一般来说图标不宜太大,如果太大了我们可以将 ...

  8. IOS图标 HTML规范,最新iOS设计规范八|3大图标和图像规范(Icons and Images)

    编辑导语:了解iOS操作系统对互联网应用开发者来说十分重要,对其有所了解,将有助于产品工作的推进,并进一步保证用户体验的优化.上篇文章里,作者对iOS系统中的视觉规范作了介绍.本篇文章作者继续对图标和 ...

  9. css 鼠标滑过li变背景图,CSS定义鼠标滑过变换背景的导航菜单

    我们经常看到的网站基本上都有导航菜单,有的网站看上去非常酷,鼠标一移动到上面自动改变颜色,这样的导航有两种方法可以实现:一种是鼠标经过图像,一种是CSS定义. 鼠标经过图像是把菜单做成两张文字相同但颜 ...

最新文章

  1. stm32官方例程在哪找_STM32开发学习资料合集
  2. JZ2440学习总结2
  3. c语言学生成绩查询课设报告,C语言课设报告(学生考试成绩查询程序)【荐】.doc...
  4. [leetcode][JAVA]面试题第[1028]题[迭代]
  5. php关闭当前页_php如何直接关闭页面注销SESSION
  6. 游戏服务器维护重启,游戏服务器需要定期重启吗
  7. NO4 findmv--特殊符号..和.
  8. android update sdk --no-ui,CircleCI Android constraintLayout不起作用
  9. B~树(B-Tree)与B+树
  10. jmeter(十三)常见问题及解决方法
  11. 奔图打印linux驱动下载,奔图P3060DW打印机驱动下载_奔图P3060DW打印机驱动官方下载-太平洋下载中心...
  12. 百度和今日头条正式开战
  13. 三星s8怎么分屏操作_三星Galaxy Z Fold2帮你应对快节奏生活
  14. excel批量文件改名批量加后缀
  15. MPP大规模并行处理架构详解(满满干货,需细嚼慢咽)
  16. 香农公式和奈氏准则描述的是同一个东西吗?
  17. 使用dscaler在windows下播放电视的设置
  18. 电脑无法连接mysql_本地电脑无法连接到MySQL
  19. 热电阻 热电偶 测量电路_热电偶和热电阻有什么区别?
  20. 诈骗团伙冒充京东金融客服来注销账号,25岁职场小伙3次转账超过3万,累计被骗14万,警方立案在线等结果,急......

热门文章

  1. iOS - Icon图标、启动图片、审核图片尺寸
  2. Linux C 两种方法实现复制拷贝文件
  3. 布袋除尘器过滤风速多少_布袋除尘器过滤风速的选择!
  4. 数字图像处理---空间滤波基础
  5. 1837:Balance
  6. 0x3f3f3f3f
  7. 0x3f3f3f3f是什么意思
  8. Lucas(卢卡斯)定理 【数论】
  9. 长春光机所计算机待遇,有谁知道长春光机所的工资待遇怎么样?硕士一年的收入大概是多少?...
  10. 一文让你秒懂FFT(快速傅里叶变换)