$(document).ready(function() { /* 完整版示例 */ // 把每个a中的内容包含到一个层(span.out)中,在span.out层后面追加背景图层(span.bg) $("#menu li a").wrapInner( '' ).append( '' ); // 循环为菜单的a每个添加一个层(span.over) $("#menu li a").each(function() { $( '' + $(this).text() + '' ).appendTo( this ); }); $("#menu li a").hover(function() { // 鼠标经过时候被触发的函数 $(".out",this).stop().animate({'top':'40px'},250); // 向下滑动 - 隐藏 $(".over",this).stop().animate({'top':'0px'},250); // 向下滑动 - 显示 $(".bg",this).stop().animate({'top':'0px'}, 120); // 向下滑动 - 显示 }, function() { // 鼠标移出时候被触发的函数 $(".out",this).stop().animate({'top':'0px'},250); // 向上滑动 - 显示 $(".over",this).stop().animate({'top':'-40px'},250); // 向上滑动 - 隐藏 $(".bg",this).stop().animate({'top':'-40px'},120); // 向上滑动 - 隐藏 }); /* 简化版示例 */ $("#menu2 li a").wrapInner( '' ); $("#menu2 li a").each(function() { $('' + $(this).text() + '' ).appendTo( this ); }); $("#menu2 li a").hover(function() { $(".out",this).stop().animate({'top':'40px'},200); // 向下滑动 - 隐藏 $(".over",this).stop().animate({'top':'0px'},200); // 向下滑动 - 显示 }, function() { $(".out",this).stop().animate({'top':'0px'},200); // 向上滑动 - 显示 $(".over",this).stop().animate({'top':'-40px'},200); // 向上滑动 - 隐藏 }); }); // 设置为主页 function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl); } catch (e) { if (window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', vrl); } else { alert("您的浏览器不支持,请按照下面步骤操作:1.打开浏览器设置。2.点击设置网页。3.输入:" + vrl + "点击确定。"); } } } // 加入收藏 兼容360和IE6 function shoucang(sTitle, sURL) { try { window.external.addFavorite(sURL, sTitle); } catch (e) { try { window.sidebar.addPanel(sTitle, sURL, ""); } catch (e) { alert("加入收藏失败,请使用Ctrl+D进行添加"); } } } $(function () { $("ul[class=nav]>li").each(function () { var html = $(this).html(); $(this).html('' + html + ''); $(this).append('' + html + ''); }); $("ul[class=nav]>li").hover(function () { $(".mouseout", this).stop().animate({ 'top': '200px' }, 300); // move down - hide $(".mouseover", this).stop().animate({ 'top': '0px' }, 300); // move down - show }, function () { $(".mouseout", this).stop().animate({ 'top': '0px' }, 300); // move up - show $(".mouseover", this).stop().animate({ 'top': '-150px' }, 300); // move up - hide }); }); $(function () { $(".backToTop").goToTop(); $(window).bind('scroll resize', function () { $(".backToTop").goToTop({ pageWidth: 1004, duration: 0 }); }); }); // JavaScript Document (function ($) { var goToTopTime; $.fn.goToTop = function (options) { var opts = $.extend({}, $.fn.goToTop.def, options); var $window = $(window); $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body'); // opera fix //$(this).hide(); var $this = $(this); clearTimeout(goToTopTime); goToTopTime = setTimeout(function () { var controlLeft; if ($window.width() > opts.pageHeightJg * 2 + opts.pageWidth) { controlLeft = ($window.width() - opts.pageWidth) / 2 + opts.pageWidth + opts.pageWidthJg; } else { controlLeft = $window.width() - opts.pageWidthJg - $this.width(); } var cssfixedsupport = $.browser.msie && parseFloat($.browser.version) < 7; //鍒ゆ柇鏄惁ie6 var controlTop = $window.height() - $this.height() - opts.pageHeightJg; controlTop = cssfixedsupport ? $window.scrollTop() + controlTop : controlTop; var shouldvisible = ($window.scrollTop() >= opts.startline) ? true : false; if (shouldvisible) { $this.stop().show(); } else { $this.stop().hide(); } $this.css({ position: cssfixedsupport ? 'absolute' : 'fixed', top: controlTop, left: controlLeft }); }, 30); $(this).click(function (event) { $body.stop().animate({ scrollTop: $(opts.targetObg).offset().top }, opts.duration); $(this).blur(); event.preventDefault(); event.stopPropagation(); }); }; $.fn.goToTop.def = { pageWidth: 910, //椤甸溃瀹藉害 pageWidthJg: 2, //鎸夐挳鍜岄〉闱㈢殑闂撮殧璺濈 pageHeightJg: 100, //鎸夐挳鍜岄〉闱㈠簳閮ㄧ殑闂撮殧璺濈 startline: 30, //鍑虹幇锲炲埌椤堕儴鎸夐挳镄勬粴锷ㄦ浔scrollTop璺濈 duration: 200, //锲炲埌椤堕儴镄勯€熷害镞堕棿 targetObg: "body"//鐩爣浣岖疆 }; })(jQuery); $(function () { $('').appendTo("body"); });