实用:JS实现鼠标悬停显示不同的页面

js|鼠标|显示|页面

当鼠标按顺序悬停在菜单上时,可在同一位置显示不同的页面

作者:Stu Nicholls 
翻译:forestgan

信息

这是 cssplay的站长根据其最近创作的dropdown and flyout menus而改编而成的,当鼠标按顺序悬停在菜单上时,可在同一位置显示不同的页面,可在Opera, IE5.5, IE6, IE7 beta,Safari 1.3.2 & Firefox.中正确显示和工作,不兼容Mac IE5。

鼠标悬停在菜单和页面上时显示文字与图片以及链接,滚动条要加在每个页上。

样式

对于非IE浏览器来说是比较简单的,只用一个样式表。

<link rel="stylesheet" media="all" type="text/css" href="one_page.css" />

/* common styling */
/* set up the overall width of the menu div, the font and the margins with a relative position*/

.menu {
font-family: verdana, arial, sans-serif;
width:750px;
margin:0;
position:relative;
}
/* remove the bullets and set the margin and padding to zero for the unordered list */
.menu ul {
padding:0;
margin:0;
list-style-type: none;
border:0;
}
/* float the list so that the items are in a line */
.menu ul li {
float:left;
}
/* style the links to be 249px wide by 30px high with a top and right border 1px solid white. Set the background color and the font size. */
.menu ul li a, .menu ul li a:visited {
display:block;
text-align:center;
text-decoration:none;
width:249px;
height:30px;
color:#000;
border:1px solid #fff;
border-width:1px 1px 0 0;
background:#c9c9a7;
line-height:30px;
font-size:11px;
}
/* make the dropdown ul invisible */
.menu ul li ul {
display: none;
}

/* specific to non IE browsers */
/* set the background and foreground color of the main menu li on hover */
.menu ul li:hover a {
color:#fff;
background:#b3ab79;
}
/* make the sub menu ul visible and position it beneath the first list item */
.menu ul li:hover ul {
text-align:left;
display:block;
position:absolute;
top:30px;
left:0;
text-align:left;
}
/* make the sub menu ul li the full width with padding and border. Add an auto scroll bar */
.menu ul li:hover ul li {
background:#eee;
color:#000;
padding:10px;
width:689px;
height:180px;
overflow:auto;
border:20px solid #b3ab79;
}
/*float the image left with padding and no border */
.menu ul li:hover ul li img {
float:left;
padding:10px 10px 10px 0;
border:0;
}
/* style the paragraph font height */
.menu ul li:hover ul li p {
font-size:0.9em;
}
/* style the background and foreground color of the submenu links */
.menu ul li:hover ul li a {
display:inline;
background:#eee;
color:#c00;
text-decoration:underline;
border:0;
}
/* style the background and forground colors of the links on hover */
.menu ul li:hover ul li a:hover {
text-decoration:none;
color:#000;
}

而IE还需要专门为它加一个,用条件判断加入。

<!--[if lte IE 6]>
  <link rel="stylesheet" media="all"   type="text/css" href="one_page_ie.css" />
<![endif]-->

/* styling specific to Internet Explorer IE5.5 and IE6. Yet to see if IE7 handles li:hover */

/* Get rid of any default table style */
table {
border-collapse:collapse;
margin:0;
padding:0;
}
/* ignore the link used by 'other browsers' */
.menu ul li a.hide, .menu ul li a:visited.hide {
display:none;
}
/* set the background and foreground color of the main menu link on hover */
.menu ul li a:hover {
color:#fff;
background:#b3ab79;
}
/* make the sub menu ul visible and position it beneath the first list item */
.menu ul li a:hover ul {
text-align:left;
display:block;
position:absolute;
top:31px;
left:0;
}

/* make the sub menu ul li the full width with padding and border. Add an auto scroll bar */
.menu ul li a:hover ul li {
background:#eee;
color:#000;
padding:10px;
width:746px;
height:240px;
overflow:auto;
border:20px solid #b3ab79;
w\idth:689px;
he\ight:180px;
}
/*float the image left with padding and no border */
.menu ul li a:hover li img {
float:left;
padding:10px 10px 10px 0;
border:0;
}
/* style the paragraph font height */
.menu ul li a:hover p {
font-size:0.7em;
f\ont-size:1em;
}
/* style the background and foreground color of the submenu links */
.menu ul li a:hover ul li a {
display:inline;
width:1px;
word-wrap:normal;
background:#eee;
color:#c00;
text-decoration:underline;
border:0;
}

/* style the background and forground colors of the links on hover */
.menu ul li a:hover ul li a:hover {
text-decoration:none;
color:#000;
}

xhtml

你会看到用条件判断来给 IE添加表格,. 其他浏览器不会用到表格,而将正常使用无序列表。文档类型声明是必须要加的,反之不能正常工作。

运行代码框

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title> stu nicholls | CSS PLaY | cross browser tabbed pages with embeded links</title><meta name="Author" content="Stu Nicholls"/><meta name="Keywords" content="cssplay, css play, Cascading, Style, Sheets, CSS1, CSS2, CSS, XHTML1.1, w3c, doing it with style, recommendations, opacity, box model, mozilla, opera, netscape, internet explorer, v6, v7.23, techniques, layout, three column, cutting edge, experimental, validation, validate, navigation, pop-up, pull-down, menus, tips, tricks, css mouseover, mouseovers, CSS experiments, CSS demonstrations"/><meta name="Description" content="CSS ~ Cutting edge Cascading Style Sheets. Experiments in CSS"/><link rel="stylesheet" media="all" type="text/css" href="http://www.forest53.com/tutorials/onepage/one_page.css"/><style type="text/css">body {text-align:center; font-family:verdana, arial, sans-serif; font-size:76%; color:#000; background:#fff url(back.gif) repeat-x; padding:0; border:0; margin:0;}</style><!--[if lte IE 6]><link rel="stylesheet" media="all" type="text/css" href="http://www.forest53.com/tutorials/onepage/one_page_ie.css" /><![endif]--><!--[if lte IE 6]><style>#ads {display:none;}#smallads {display:none;}#adsie {clear:both; text-align:center; width:750px; margin-top:10px;}#smalladsie {clear:both; text-align:center; width:468px; margin-top:10px;}</style><![endif]--></head><body> <div class="menu" style="margin: 10px auto;"> <ul> <li><a class="hide" href="#nogo">John Constable</a> <!--[if lte IE 6]><a href="../menu/index.html">John Constable<table><tr><td><![endif]--> <ul> <li> <p>Although he showed an early talent for art and began painting his native Suffolk scenery before he left school, his great originality matured slowly.</p> <img src="http://www.webjx.com/htmldata/2006-03-28/constable.jpg" alt="The Hay Wain" title="The Hay Wain"/> <p>He committed himself to a career as an artist only in 1799, when he joined the Royal Academy Schools and it was not until 1829 that he was grudgingly made a full Academician, elected by a majority of only one vote.</p> <p>In 1816 he became financially secure on the death of his father and married Maria Bicknell after a seven-year courtship and in the fact of strong opposition from her family. During the 1820s he began to win recognition: The Hay Wain (National Gallery, London, 1821) won a gold medal at the Paris Salon of 1824 and Constable was admired by <a href="http://www.ibiblio.org/wm/paint/auth/delacroix/">Delacroix</a> and Bonington among others.</p> <p>His wife died in 1828, however, and the remaining years of his life were clouded by despondency.</p> <p>This text is an excerpt from <a href="http://www.ibiblio.org/wm/paint/auth/constable/">The WebMuseum, Paris</a></p> </li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--> </li> <li><a class="hide" href="#nogo">Claude Monet</a> <!--[if lte IE 6]><a href="#nogo">Claude Monet<table><tr><td><![endif]--> <ul> <li> <p>His youth was spent in Le Havre, where he first excelled as a caricaturist but was then converted to landscape painting by his early mentor <a href="http://www.ibiblio.org/wm/paint/auth/boudin/">Boudin</a>, from whom he derived his firm predilection for painting out of doors.</p> <img src="http://www.webjx.com/htmldata/2006-03-28/monet.jpg" alt="Women in the Garden" title="Women in the Garden"/> <p>In 1859 he studied in Paris at the Atelier Suisse and formed a friendship with <a href="http://www.ibiblio.org/wm/paint/auth/pissarro/">Pissarro</a>. After two years' military service in Algiers, he returned to Le Havre and met <a href="http://www.ibiblio.org/wm/paint/auth/jongkind/">Jongkind</a>, to whom he said he owed `the definitive education of my eye'.</p> <p>He then, in 1862, entered the studio of Gleyre in Paris and there met Renoir, Sisley, and Bazille, with whom he was to form the nucleus of the Impressionist group.</p> <p>Monet's devotion to painting out of doors is illustrated by the famous story concerning one of his most ambitious early works, Women in the Garden (Musée d'Orsay, Paris; 1866-67). The picture is about 2.5 meters high and to enable him to paint all of it outside he had a trench dug in the garden so that the canvas could be raised or lowered by pulleys to the height he required.</p> <p><a href="http://www.ibiblio.org/wm/paint/auth/courbet/">Courbet</a> visited him when he was working on it and said Monet would not paint even the leaves in the background unless the lighting conditions were exactly right.</p> <p>This text is an excerpt from <a href="http://www.ibiblio.org/wm/paint/auth/monet/">The WebMuseum, Paris</a></p> </li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--> </li> <li><a class="hide" href="#nogo">Vincent Van Gogh</a> <!--[if lte IE 6]><a href="../layouts/index.html">Vincent Van Gogh<table><tr><td><![endif]--> <ul> <li> <p>Gogh, Vincent (Willem) van (b. March 30, 1853, Zundert, Neth.--d. July 29, 1890, Auvers-sur-Oise, near Paris), generally considered the greatest Dutch painter and draughtsman after <a href="http://www.ibiblio.org/wm/paint/auth/rembrandt/">Rembrandt</a>.</p> <img src="http://www.webjx.com/htmldata/2006-03-28/vincent.jpg" alt="The Starry Night" title="The Starry Night"/> <p>With <a href="http://www.ibiblio.org/wm/paint/auth/cezanne/">Cézanne</a> and <a href="http://www.ibiblio.org/wm/paint/auth/gauguin/">Gauguin</a> the greatest of Post-Impressionist artists. He powerfully influenced the current of <a href="http://www.ibiblio.org/wm/paint/glo/expressionism/">Expressionism</a> in modern art. His work, all of it produced during a period of only 10 years, hauntingly conveys through its striking colour, coarse brushwork, and contoured forms the anguish of a mental illness that eventually resulted in suicide. Among his masterpieces are numerous self-portraits and the well-known <a href="http://www.ibiblio.org/wm/paint/auth/gogh/starry-night/">The Starry Night</a> (1889).</p> <p>This text is an excerpt from <a href="http://www.ibiblio.org/wm/paint/auth/gogh/">The WebMuseum, Paris</a></p> </li> </ul> <!--[if lte IE 6]></td></tr></table></a><![endif]--> </li> </ul> <div class="clear"> </div> </div></body></html>

    [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

时间: 2024-12-30 19:18:51

实用:JS实现鼠标悬停显示不同的页面的相关文章

CSS或者JS实现鼠标悬停显示另一元素_javascript技巧

想达到鼠标悬停到元素a上,显示另一个元素b,可以通过css实现也可以通过js实现. js: 写两个函数:mouseenter,mouseleave,例如:其中 $("#a").mouseenter(function() { $("#b").show("normal"); }); $("#a").mouseleave(function() { $("#b").hide("normal");

jQuery实现鼠标悬停显示提示信息窗口的方法

  本文实例讲述了jQuery实现鼠标悬停显示提示信息窗口的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xht

Javascript仿新浪游戏频道鼠标悬停显示子菜单效果_javascript技巧

本文实例讲述了Javascript仿新浪游戏频道鼠标悬停显示子菜单效果,分享给大家供大家参考.具体如下: 这里演示使用JS实现的网页栏目分类菜单,从新浪游戏频道扣下来的,操作方式类似于滑动门的效果,鼠标无需点击,只需把鼠标放在一级主菜单上,就可显示出二级分类菜单,这弹出的这个二级菜单中,实际上又重新进行了分类,可以说整体上,这是一款支持三级分类的网站菜单,目前新浪游戏还在用的效果哦. 先来看运行效果截图: 在线演示地址如下: http://demo.jb51.net/js/2015/js-gam

WordPress中鼠标悬停显示和隐藏评论及引用按钮的实现_javascript技巧

根据鼠标悬停显示.隐藏,回复和引用按钮思路及原理 原理嘛很简单,如果你阅读过一页或者两页甚至更多页 Jquery 手册的话, 那么下面的原理解释你肯定能看懂,否则请跳至代码实现区域阅读. 思路很简单, 将回复.引用按钮放置在你想要的地方,CSS 样式设置 display:none; 绑定Jquery中的hover动作到你想要鼠标悬停后显示按钮的区域 是不是很简单?要是我以前写博客肯定会就此结束, 好吧,既然授人鱼那么继续--. 特效的代码实现部分 回复.引用的HTML代码 复制代码 代码如下:

Bootstrap导航条可点击和鼠标悬停显示下拉菜单的实现代码_javascript技巧

使用Bootstrap导航条组件时,如果你的导航条带有下拉菜单,那么这个带下拉菜单的导航在点击时只会浮出下拉菜单,它本身的href属性会失效,也就是失去了超链接功能,这并不是我想要的,我希望导航条的链接可以正常打开它的链接,但又需要下拉菜单功能,开始折腾~ 首先解决带下拉菜单的导航条可以点击问题,下拉菜单效果是JS实现的,分析bootstrap.js文件发现,Bootstrap把下拉菜单写成了一个JQuery插件,在dropdown代码段中找到了关键的几句: // APPLY TO STANDA

jQuery实现鼠标悬停显示提示信息窗口的方法_jquery

本文实例讲述了jQuery实现鼠标悬停显示提示信息窗口的方法.分享给大家供大家参考.具体实现方法如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"

js实现鼠标悬停图片上时滚动文字说明的方法

 这篇文章主要介绍了js实现鼠标悬停图片上时滚动文字说明的方法,涉及js操作鼠标事件的使用技巧,需要的朋友可以参考下     本文实例讲述了js实现鼠标悬停图片上时滚动文字说明的方法.分享给大家供大家参考.具体实现方法如下:   代码如下: <html> <title>js实现鼠标悬停图片上时的滚动文字说明</title> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin

js实现鼠标悬停图片上时滚动文字说明的方法_javascript技巧

本文实例讲述了js实现鼠标悬停图片上时滚动文字说明的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: <html> <title>js实现鼠标悬停图片上时的滚动文字说明</title> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function showtip2(current,e,text){   if (document.all&&a

js-asp.net 鼠标悬停显示我自己在后台写的一些信息

问题描述 asp.net 鼠标悬停显示我自己在后台写的一些信息 悬停之后我想显示一些信息,这些信息是后台写的,类似于姓名啊,性别啊,年龄啊,top.left(动态改变的),我希望在图片上方或者旁边显示,不想在图片上显示,求大神指点! 解决方案 为图片加tooltip属性就行了吧 解决方案二: http://download.csdn.net/download/nancynancy1981/2024218 参考这个例子 用弹出层,你可以用css控制它的位置啦.