jQuery实现垂直滚动菜单效果特效代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 jQuery实现垂直滚动菜单效果特效代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

jQuery实现垂直滚动菜单效果特效代码

HTML代码(index.html):

<!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">
<head>
<title>jQuery实现垂直滚动菜单效果</title>
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.color.js"></script>
<script type="text/javascript">


$(document).ready(function() {	

	//Background color, mouseover and mouseout
	var colorOver = '#31b8da';
	var colorOut = '#1f1f1f';

	//Padding, mouseover
	var padLeft = '20px';
	var padRight = '20px';
	
	//Default Padding
	var defpadLeft = $('#menu li a').css('paddingLeft');
	var defpadRight = $('#menu li a').css('paddingRight');
		
	//Animate the LI on mouse over, mouse out
	$('#menu li').click(function () {	
		//Make LI clickable
		window.location = $(this).find('a').attr('href');
		
	}).mouseover(function (){
		
		//mouse over LI and look for A element for transition
		$(this).find('a')
		.animate( { paddingLeft: padLeft, paddingRight: padRight}, { queue:false, duration:100 } )
		.animate( { backgroundColor: colorOver }, { queue:false, duration:200 });

	}).mouseout(function () {
	
		//mouse oout LI and look for A element and discard the mouse over transition
		$(this).find('a')
		.animate( { paddingLeft: defpadLeft, paddingRight: defpadRight}, { queue:false, duration:100 } )
		.animate( { backgroundColor: colorOut }, { queue:false, duration:200 });
	});	
	
	//Scroll the menu on mouse move above the #sidebar layer
	$('#sidebar').mousemove(function(e) {

		//Sidebar Offset, Top value
		var s_top = parseInt($('#sidebar').offset().top);		
		
		//Sidebar Offset, Bottom value
		var s_bottom = parseInt($('#sidebar').height() + s_top);
	
		//Roughly calculate the height of the menu by multiply height of a single LI with the total of LIs
		var mheight = parseInt($('#menu li').height() * $('#menu li').length);
	
		//I used this coordinate and offset values for debuggin
		$('#debugging_mouse_axis').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
		$('#debugging_status').html(Math.round(((s_top - e.pageY)/100) * mheight / 2));
			
		//Calculate the top value
		//This equation is not the perfect, but it 's very close	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 2);
		
		//Animate the #menu by chaging the top value
		$('#menu').animate({top: top_value}, { queue:false, duration:500});
	});

	
});
	
</script>

<style>
body {
padding:0;
margin:0 20px;
}

#sidebar {
height:400px;
overflow:hidden;
position:relative;
background-color:#eee;
}	

#menu {
width:100%;
list-style:none;
padding:0;
margin:0;
top:0;
position:relative;
height:100%;
width:300px;
}

#menu li {
padding:10px 0;
text-align:right;
display:block;
cursor:hand;
cursor:pointer;
}

#menu li a {
background:url() repeat #1f1f1f;

color:#ddd;
font-family:helvetica, arial, verdana;
font-size:9px;
font-weight:900;
display:inline;
padding:20px 8px 5px 20px;
text-decoration:none;
}

#menu li span {
font-family:georgia, arial;
font-size:9px;
color:#464646;
}

</style>
</head>

<div id="debugging_mouse_axis"></div>
<div id="debugging_status"></div>
<div id="sidebar">
<ul id="menu">
<li><a href="#">MENU 1 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 2 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 3 <span> / 2014</span></a></li>
<li><a href="#">MENU 4 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 5 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 6 <span> / 2014</span></a></li>
<li><a href="#">MENU 7 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 8 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 9 <span> / 2014</span></a></li>
<li><a href="#">MENU 10 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 11 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 12 <span> / 2014</span></a></li>
<li><a href="#">MENU 13 <span> / 2014</span></a></li>
<li><a href="#">SUPER LONG MENU MENU MENU MENU SIZE 14 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 15 <span> / 2014</span></a></li>
<li><a href="#">MENU 16 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 17 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 18 <span> / 2014</span></a></li>
<li><a href="#">MENU 19 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 20 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 21 <span> / 2014</span></a></li>
<li><a href="#">MENU 22 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 5 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 23 <span> / 2014</span></a></li>
<li><a href="#">MENU 24 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 25 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 26 <span> / 2014</span></a></li>
<li><a href="#">MENU 27 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 28 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 29 <span> / 2014</span></a></li>
<li><a href="#">MENU 30 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 31 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 32 <span> / 2014</span></a></li>
<li><a href="#">MENU 33 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE 34 <span> / 2014</span></a></li>
<li><a href="#">MENU SIZE LONG 35 <span> / 2014</span></a></li>
</ul>
</div>
</body>
</html>








JS代码(jquery.color.js):

/* * jQuery Color Animations * Copyright 2007 John Resig * Released under the MIT and GPL licenses. */
(function(jQuery){
	// We override the animation for all of these color stylesjQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){
	jQuery.fx.step[attr] = function(fx){
	if ( fx.state == 0 ){
	fx.start = getColor( fx.elem,attr );
	fx.end = getRGB( fx.end );
}
fx.elem.style[attr] = "rgb(" + [Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]),255),0),Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]),255),0),Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]),255),0)].join(",") + ")";
}
}
);
	// Color Conversion functions from highlightFade// By Blair Mitchelmore// http://jquery.offput.ca/highlightFade/// Parse strings looking for color tuples [255,255,255]function getRGB(color){
	var result;
	// Check if we're already dealing with an array of colorsif ( color && color.constructor == Array && color.length == 3 )return color;
	// Look for rgb(num,num,num)if (result = /rgb\(\s*([0-9]{
	1,3}
)\s*,\s*([0-9]{
	1,3}
)\s*,\s*([0-9]{
	1,3}
)\s*\)/.exec(color))return [parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];
	// Look for rgb(num%,num%,num%)if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))return [parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];
	// Look for #a0b1c2if (result = /#([a-fA-F0-9]{
	2}
)([a-fA-F0-9]{
	2}
)([a-fA-F0-9]{
	2}
)/.exec(color))return [parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];
	// Look for #fffif (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))return [parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];
	// Otherwise,we're most likely dealing with a named colorreturn colors[jQuery.trim(color).toLowerCase()];
}
function getColor(elem,attr){
	var color;
	do{
	color = jQuery.curCSS(elem,attr);
	// Keep going until we find an element that has color,or we hit the bodyif ( color != '' && color != 'transparent' || jQuery.nodeName(elem,"body") )break;
	attr = "backgroundColor";
}
while ( elem = elem.parentNode );
	return getRGB(color);
}
;
	// Some named colors to work with// From Interface by Stefan Petre// http://interface.eyecon.ro/var colors ={
	aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}
;
}
)(jQuery);
	
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
23.86 KB
Html Js 菜单导航特效2
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章