gpt4 book ai didi

jquery - "Mega"下拉菜单

转载 作者:行者123 更新时间:2023-11-28 11:51:14 25 4
gpt4 key购买 nike

我正在制作一个“大型”下拉菜单。但是,我需要对其进行一点改动,这被证明是一项任务。

要被认为是正确的,它应该如下所示并且每个选项卡下拉列表都需要显示在同一位置,因为它们每个都包含相似的信息。下拉列表的左侧应从大图像的左侧开始。

alt text http://egdata.com/Cory/mdd.jpg

请注意,悬停主选项卡时将显示所有 5 个子区域。这只是一个 2 级下拉菜单。

目前在IE8、FF、Opera中正确,在Chrome、IE7、IE6中错误。这 3 个“错误”的浏览器都呈现出几乎相同的效果。

如有任何帮助,我们将不胜感激。我很确定这是我一直想念的小东西。


快速通用结构

ul#MM
li.mega h2 a
div.subMenu
div.mini
h3
ul.sub
li a

CSS

body { background:#FFFFFF; color:#343434; font-size:14px; font-family:Verdana, Geneva, sans-serif; margin:0; padding:0; }

ul#MM { }
ul#MM li { display: inline; position: relative; padding:0; margin:0; overflow:hidden; }
ul#MM h2 { font-size:100%; font-weight: normal; display:inline; line-height:24px; }
ul#MM h3 { font-size:100%; font-weight: normal; display:inline; padding:5px; margin:0; color:#fff; }
ul#MM li a { color:#0086aa; text-decoration:none; }
ul#MM li a:hover { text-decoration:none; }
ul#MM li.mega a { background:transparent url(arrow.gif) center right no-repeat; padding:8px 5px; }
ul#MM li.mega a:hover { text-decoration:none; background:url(blueTrandBG.png) repeat; color:#fff;}
ul#MM li.mega h2 a.current { text-decoration:none; background:url(blueTrandBG.png) repeat; color:#fff; padding:8px 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; border-top-left-radius:5px; border-top-right-radius:5px; }

ul#MM li.mega div.subMenu { display:none; position: absolute; top:25px; margin:0; padding:10px; width:960px; height:366px; background:url(blueTrandBG.png) repeat; border-radius:5px; -webkit-border-radius:5px; -moz-border-radius:5px;}

ul#MM li.mega div.subMenu div.mini { width:168px; float:left; margin:5px; position:relative; background:url(blueTrandBG_lite.png) repeat; padding:5px; border-radius:5px; -webkit-border-radius:5px; -moz-border-radius:5px; }
ul#MM li.mega div.subMenu div.mini:hover { background:url(blueTrandBG.png) repeat; }

ul#MM li.hovering div.subMenu { display:block; margin:0; }

ul#MM li.mega div.subMenu ul.sub { background:#fff; padding:0; margin:0; display:block; border-radius:5px; -webkit-border-radius:5px; -moz-border-radius:5px; }
ul#MM li.mega div.subMenu ul.sub li { border-bottom:1px solid #eaeaea; padding:0; margin:0; list-style:none; width:100%; display:block; }
ul#MM li.mega div.subMenu ul.sub li a { display:block; background:transparent; margin:0; border:0; padding:6px; color:#221f1f; }
ul#MM li.mega div.subMenu ul.sub li a:hover { color:#f37928; background:transparent; }

#box { margin:0 auto; padding:0; width:960px; }
#bigPicture { width:960px; height:351px; background-color:#000; margin-left:-7px; margin-top:20px; }
.grayLight { color:#777; }

HTML/JS

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="css-02.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script>
/** hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+ <http://cherne.net/brian/resources/jquery.hoverIntent.html> @author Brian Cherne <brian@cherne.net> */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
</script>
<script type="text/javascript">
$(document).ready(function() {
function addMega(){
$(this).children("h2").children().addClass("current");
$(this).addClass("hovering");
var subMenu = $(this).children("ul#MM li.hovering div.subMenu");
// var pos = $(this).offset();
// var width = $(this).width();
// alert(pos.left);
// subMenu.children("ul").css( { "left": "0", "top":"50px" } );
subMenu.show();
subMenu.css("marginLeft", "-50px");
}

function removeMega(){
$(this).children("h2").children().removeClass("current");
$(this).removeClass("hovering");
}

var megaConfig = {
interval: 100,
sensitivity: 10,
over: addMega,
timeout: 250,
out: removeMega
};

$("li.mega").hoverIntent(megaConfig);
$("ul#MM li.mega div ul li:last-child").css("borderWidth",0);

if ($.browser.opera) {
$("ul#MM li.mega div.subMenu").css("top", "33px");
$("ul#MM li.mega div.mini").css("top", "0");
}
});
</script>
<!--[if lte IE 7]> <style type="text/css">ul#MM li.mega div.subMenu { top:33px; left:0; } </style><![endif]-->
</head>
<body>
<div id="box">
<ul id="MM">
<li>
<h2><a href="./">home</a></h2>
</li>
<li><span class="grayLight">|</span></li>
<li class="mega">
<h2><a href="play.cfm">plays</a></h2>
<div class="subMenu">
<div class="mini">
<h3>play</h3>
<ul class="sub">
<li><a href="bay_fishing.cfm">bay fishing</a></li>
<li><a href="deep_sea_fishing.cfm">deep sea fishing</a></li>
<li><a href="fly_fishing.cfm">fly fishing</a></li>
<li><a href="floundering.cfm">floundering</a></li>
<li><a href="fresh_water_fishing.cfm">fresh water fishing</a></li>
<li><a href="jetty_fishing.cfm">jetty fishing</a></li>
<li><a href="kayak_fishing.cfm">kayak fishing</a></li>
<li><a href="surf_fishing.cfm">surf fishing</a></li>
<li><a href="pier_fishing.cfm">pier fishing</a></li>
</ul>
</div>
<div class="mini">
<h3>hiy</h3>
<ul class="sub">
<li><a href="species.cfm">species</a></li>
<li><a href="bag_limits.cfm">bag limits</a></li>
<li><a href="photo_gallery.cfm">photo gallery</a></li>
</ul>
</div>
<div class="mini">
<h3>hellj</h3>
<ul class="sub">
<li><a href="when_to_come.cfm">when to come</a></li>
<li><a href="where_to_go.cfm">where to go</a></li>
<li><a href="hot_spots.cfm">hot spots</a></li>
<li><a href="boat_ramps_marinas.cfm">boat ramps &amp; marinas</a></li>
<li><a href="guides.cfm">guides</a></li>
<li><a href="bait_shops.cfm">bait shops</a></li>
<li><a href="what_to_bring.cfm">what to bring</a></li>
<li><a href="boater_s_checklist.cfm">boater's checklist</a></li>
</ul>
</div>
<div class="mini">
<h3>there</h3>
<ul class="sub">
<li><a href="seagrass_protection.cfm">seagrass protection</a></li>
</ul>
</div>
<div class="mini">
<h3>wow</h3>
<ul class="sub">
<li><a href="round_the_bend.cfm">round the bend</a></li>
</ul>
</div>
</div>
</li>
<li><span class="grayLight">|</span></li>
<li class="mega">
<h2><a href="learn.cfm">learn</a></h2>
<div class="subMenu">
<div class="mini">
<h3>play</h3>
<ul class="sub">
<li><a href="bay_fishing.cfm">bay fishing</a></li>
<li><a href="deep_sea_fishing.cfm">deep sea fishing</a></li>
<li><a href="fly_fishing.cfm">fly fishing</a></li>
<li><a href="floundering.cfm">floundering</a></li>
<li><a href="fresh_water_fishing.cfm">fresh water fishing</a></li>
<li><a href="jetty_fishing.cfm">jetty fishing</a></li>
<li><a href="kayak_fishing.cfm">kayak fishing</a></li>
<li><a href="surf_fishing.cfm">surf fishing</a></li>
<li><a href="pier_fishing.cfm">pier fishing</a></li>
</ul>
</div>
<div class="mini">
<h3>hiy</h3>
<ul class="sub">
<li><a href="species.cfm">species</a></li>
<li><a href="bag_limits.cfm">bag limits</a></li>
<li><a href="photo_gallery.cfm">photo gallery</a></li>
</ul>
</div>
<div class="mini">
<h3>hellj</h3>
<ul class="sub">
<li><a href="when_to_come.cfm">when to come</a></li>
<li><a href="where_to_go.cfm">where to go</a></li>
<li><a href="hot_spots.cfm">hot spots</a></li>
<li><a href="boat_ramps_marinas.cfm">boat ramps &amp; marinas</a></li>
<li><a href="guides.cfm">guides</a></li>
<li><a href="bait_shops.cfm">bait shops</a></li>
<li><a href="what_to_bring.cfm">what to bring</a></li>
<li><a href="boater_s_checklist.cfm">boater's checklist</a></li>
</ul>
</div>
<div class="mini">
<h3>there</h3>
<ul class="sub">
<li><a href="seagrass_protection.cfm">seagrass protection</a></li>
</ul>
</div>
<div class="mini">
<h3>wow</h3>
<ul class="sub">
<li><a href="round_the_bend.cfm">round the bend</a></li>
</ul>
</div>
</div>
</li>
<li><span class="grayLight">|</span></li>
<li>
<h2><a href="plan.cfm">plan</a></h2>
</li>
<li><span class="grayLight">|</span></li>
<li class="mega">
<h2><a href="conserve.cfm">conserve</a></h2>
<div class="subMenu">
<div class="mini">
<h3>play</h3>
<ul class="sub">
<li><a href="bay_fishing.cfm">bay fishing</a></li>
<li><a href="deep_sea_fishing.cfm">deep sea fishing</a></li>
<li><a href="fly_fishing.cfm">fly fishing</a></li>
<li><a href="floundering.cfm">floundering</a></li>
<li><a href="fresh_water_fishing.cfm">fresh water fishing</a></li>
<li><a href="jetty_fishing.cfm">jetty fishing</a></li>
<li><a href="kayak_fishing.cfm">kayak fishing</a></li>
<li><a href="surf_fishing.cfm">surf fishing</a></li>
<li><a href="pier_fishing.cfm">pier fishing</a></li>
</ul>
</div>
<div class="mini">
<h3>hiy</h3>
<ul class="sub">
<li><a href="species.cfm">species</a></li>
<li><a href="bag_limits.cfm">bag limits</a></li>
<li><a href="photo_gallery.cfm">photo gallery</a></li>
</ul>
</div>
<div class="mini">
<h3>hellj</h3>
<ul class="sub">
<li><a href="when_to_come.cfm">when to come</a></li>
<li><a href="where_to_go.cfm">where to go</a></li>
<li><a href="hot_spots.cfm">hot spots</a></li>
<li><a href="boat_ramps_marinas.cfm">boat ramps &amp; marinas</a></li>
<li><a href="guides.cfm">guides</a></li>
<li><a href="bait_shops.cfm">bait shops</a></li>
<li><a href="what_to_bring.cfm">what to bring</a></li>
<li><a href="boater_s_checklist.cfm">boater's checklist</a></li>
</ul>
</div>
<div class="mini">
<h3>there</h3>
<ul class="sub">
<li><a href="seagrass_protection.cfm">seagrass protection</a></li>
</ul>
</div>
<div class="mini">
<h3>wow</h3>
<ul class="sub">
<li><a href="round_the_bend.cfm">round the bend</a></li>
</ul>
</div>
</div>
</li>
<li><span class="grayLight">|</span></li>
<li>
<h2><a href="learn.cfm">learn</a></h2>
</li>
<li><span class="grayLight">|</span></li>
<li>
<h2><a href="plan.cfm">plan</a></h2>
</li>
<li><span class="grayLight">|</span></li>
<li>
<h2><a href="stay.cfm">stay</a></h2>
</li>
</ul>
<div id="bigPicture" style="background-image:url(http://www.visitcorpuschristitx.org/birding/images/bigimage5.jpg)">
<div id="megaMenu"></div>
</div>
</div>
</body>
</html>

最佳答案

这里的问题太多了,无法在一个答案中提供适用于所有浏览器的解决方案。

但是,您的下拉菜单布局问题的关键在于下拉菜单 DIV 的哪个父元素相对定位。当前是 LI 元素,要实现您想要的布局,它应该是 UL 元素。因此,Safari(可能还有其他 Webkit 浏览器)的解决方案的开始是这样的:

  • 将这一行从你的Javascript:

    subMenu.css("marginLeft", "-50px");

  • 添加/更改这些 CSS 声明:

    ul#MM { position:relative; }

    ul#MM li.mega { 位置:静态; }

    ul#MM li.mega div.subMenu { left: 0;顶部:2em; }

关于jquery - "Mega"下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1947131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com