index.js 7.83 KB
/**
 * @author zzf
 */
  
   //浏览器宽度变化页面的变化
$(function(){
	function autoWidth(){
		var _win = $(window).width();
		var w1200 = 1200;
		var w990 = 990;
		if(_win >= 1300){
			setWin(w1200);
			$(".serve .serve-tr2 a").css("margin","0 13px");
			$(".un-pref-cent ul li").css("margin","0 10px 0 11px");
			$(".un-boxlist ul li").css("margin","0 7px");
			$(".header-mo .mo-fn2").css("margin-left","215px");
			$('.site').css("right",(((_win - w1200) / 2) - 70)+"px");
			$('.pack-a').hide();
			$('.pack-box em').hide();
			$('.pack-mo').show();
			$('.nav-box').width(680);
		}else{
			setWin(w990);
			$(".serve .serve-tr2 a").css("margin","0");
			$(".un-pref-cent ul li").css("margin","0 5px");
			$(".un-boxlist ul li").css("margin","0 4px");
			$(".header-mo .mo-fn2").css("margin-left","120px");
			$('.site').css("right","50px");
			$('.pack-a').show();
			$('.pack-box em').show();
			$('.pack-mo').hide();
			$('.nav-box').width(710);
		};
		
		function setWin(_wid){
			$('.auto-w').width(_wid);
			$('.serve').width(_wid - 260);
			$('.hot').width(_wid - 260);
			$('.un-pref-cent').width(_wid - 488);
		};
		
	};
	autoWidth();//初始化
	$(window).resize(autoWidth);
	
	$("img").lazyload();
	
	$('.imglist_w').dilislider({
		time:3000,
		pointPage : 21,
		direction : 'fading',
		ispont : true
	});
	
	//首页新闻隐藏显示
	$(".pack-box em").toggle(
		function(){
			$(this).addClass("on");
			$(this).parent().addClass("reveal");
			$(this).next(".pack-a").hide();
			$(this).nextAll(".pack-mo").show();
		},
		function(){
			$(this).removeClass("on");
			$(this).parent().removeClass("reveal");
			$(this).next(".pack-a").show();
			$(this).nextAll(".pack-mo").hide();
		}
	);
	$(".pack-a").bind("click",function(){
		$(".pack-box em").click();
	});
	//资讯、公告展示区
	$(".pack-mo-tr2 span a").bind("hover",function(){
		var i = $(".pack-mo-tr2 span a").index(this);
		$(".pack-mo-tr2 span a").removeClass("on");
		$(this).addClass("on");
		$(".pack-mo-tr2 ul").hide();
		$(".pack-mo-tr2 ul").eq(i).show();
	});
	//加入进货栏
	$(".un-boxlist li a").dhover(
		function(){
			$(this).find(".shine").stop();
			$(this).find(".shine").css('left', '-160px').animate({"left": '160px'}, 500);
			$(this).next('.info').stop().animate({"top":"130px"});
			return false;
		},
		function(){
			$(this).next('.info').stop().animate({"top":"170px"});
			return false;
		}
	);
	//页面定位以及显示
	$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
	$('.site-list a').click(function(){
		var key = $(this).attr('href');
		key = key.split('#')[1];
		var sll = $('#'+key).offset().top - 300;
		$body.animate({scrollTop: sll}, 1000);key
		
		return false;
	});
	
	function indexSerIcon(obj_tree,obj_dom){
		if(obj_tree!=''){
			_dom=$(obj_tree);
			_dom.find(obj_dom).bind("mouseover",function(){
		        if(!($(this).is(":animated"))){  
		            $(this).animate({"marginTop":"-25px","opacity":"hide"},200).animate({"marginTop":"20px","opacity":"hide"},0).animate({"marginTop":"0","opacity":"show"},200).animate({"marginTop":"-0px"},200);  
				}  
		    });  
		}
	};
	indexSerIcon(".serve-tr2","img");
	
	//滚动事件监听
	var isHFixed = true;
	var box_left = 13;
	$(window).scroll(function (){
		var _scl = $(window).scrollTop();
		if(_scl == 0){
			$('.site-list a.a-top').hide(300);
		}else{
			$('.site-list a.a-top').show(300);
		}
		if(_scl > 0 && isHFixed){
			isHFixed = false;
			$('.h-fixed').css({'position':'fixed', 'border-bottom':'1px solid #DDDDDD', 'height':'30px', 'box-shadow':'0 1px 5px rgba(0, 0, 0, 0.1)', 'z-index':9999})
			.find('.header-mo').css({'height':'55px', 'padding-top':'5px'}).find('.mo-fn1').find('a').css({'width':'120px', 'height':'40px', 'margin-top':'4px'});
			
			$('.h-fixed').animate({'height':'90px'}, 250, function(){
				box_left = $('.a-tit').offset().left;
				//$('.header-mo .mo-fn3 span.a-tit').css({'position':'fixed', 'left':box_left+'px'});
			});
			$(".autocomplete-suggestions").css({'position':'fixed','top':'80px'});
		}else if(_scl == 0){
			isHFixed = true;
			$('.h-fixed').css({'position':'relative', 'border-bottom':'none', 'height':'140px', 'box-shadow':'none', 'z-index':999})
			.find('.header-mo').css({'height':'78px', 'padding-top':'32px'}).find('.mo-fn1').find('a').css({'width':'150px', 'height':'50px', 'margin-top':'0px'});
			box_left = 13;
			//$('.header-mo .mo-fn3 span.a-tit').css({'position':'absolute', 'left':box_left+'px'});
			$(".autocomplete-suggestions").css({'position':'absolute','top':'107px'});
		};
		switch(true){
		  case (_scl <= 1400 && _scl > 900) : 
		  		showAct(1);
		    break;
		  case (_scl <= 2040 && _scl > 1400): 
		  		showAct(2);
		    break;
		  case (_scl <= 2600 && _scl > 2040): 
		  		showAct(3);
		    break;
		  case (_scl <= 3100 && _scl > 2600): 
		  		showAct(4);
		    break;
		  case (_scl <= 3700 && _scl > 3100): 
		  		showAct(5);
		    break;
		  case (_scl <= 4000 && _scl > 3700): 
		  		showAct(6);
		    break; 
		  default:
		  		showAct(0);
		};
		
		function showAct (key){
			$('.wid-hover').eq(key).addClass('showed');
			$('.site-list li a').removeClass('act');
			$('.sl-a'+key+' a').addClass('act');
		};
	});
	
	
	//加入购物车动画
	// 元素以及其他一些变量
	var eleFlyElement = $('#shopping-am')[0], eleShopCart = $('.a-tit')[0];
	var numberItem = 0;
	// 抛物线运动
	var myParabola = funParabola(eleFlyElement, eleShopCart, {
		speed: 700,
		curvature: 0.0005,	
		complete: function() {
			eleFlyElement.style.visibility = "hidden";
			$('.mo-fn3 b').html('('+(++numberItem)+')');
			shake('a-tit');
		}
	});
	// 绑定点击事件
	if (eleFlyElement && eleShopCart) {
		$('.add-shopping').click(function(event) {
			// 滚动大小
			$('#shopping-am').find('img').attr('src', $(this).prev().attr('src'));
			var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
			    scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
			eleFlyElement.style.left = event.clientX + "px";
			eleFlyElement.style.top = event.clientY  + "px";
			eleFlyElement.style.visibility = "visible";
			// 需要重定位
			myParabola.position().move();	
			
			return false;		
		});
	}
	
	function shake(o){
	    var $panel = $("."+o);
	    if($panel.css('position') == 'absolute'){
	    	box_left = 13;
	    }else{
	    	box_left = $panel.offset().left;
	    };
	    $panel.css({'left': box_left});
	    for(var i=1; 3 >= i; i++){
	        $panel.animate({left:box_left+(1*i)},50);
	        $panel.animate({left:box_left-(1*i)},50);
	        if(i == 3){
	        	 $panel.animate({left:box_left},50);
	        };
	    }
	}
	
	function ifloat(n){
		var tag = $('.'+n);
		tag.hover(function(){	
			if ($(this).find('i').css('top')=='0px'){
				$(this).find('i').animate({top:'-3px'}, 200);
			}
		},function(){
			$(this).find('i').animate({top:'0px'}, 200);
		});
	}
	ifloat('m-left li')
	
	$('.un-pref-left').live('mouseover', function(){
		Tools.amHover($(this).parent().parent().find('.un-title em'), 'bounce');
	});
	
	$('.a-pic').hover(function(){
		$(this).find('.a-pri').animate({marginTop : '-45px', left : '80px'}, 'fast');
		$(this).find('.a-pri .rmb').animate({opacity : '1'}, 'normal');
		$(this).find('img').animate({top : '-10px'}, 'fast');
	},function(){
		$(this).find('.a-pri').animate({marginTop : '-18px', left : '0px'}, 'fast');
		$(this).find('.a-pri .rmb').animate({opacity : '0'}, 'normal');
		$(this).find('img').animate({top : '0px'}, 'fast');
	});
	
	$('.a-pic-1').hover(function(){
		$(this).find('.a-tt-1').animate({marginTop : '-31px'}, 'fast');
		$(this).find('.a-pri-1').animate({left : '0px'}, 'fast');
		$(this).find('img').animate({top : '-10px'}, 'fast');
	},function(){
		$(this).find('.a-tt-1').animate({marginTop : '10px'}, 'fast');
		$(this).find('.a-pri-1').animate({left : '-12px'}, 'fast');
		$(this).find('img').animate({top : '0px'}, 'fast');
	});

});