$(function(){ $('header .lines').on('click',function(){ $('header .nav').stop().slideToggle(); $('.headerbg').stop().slideToggle(); if ($(this).hasClass('cur')) { $(this).removeClass('cur'); } else{ $(this).addClass('cur'); }; }) $('header .nav li').on('click',function(){ if ($(this).hasClass('cur')) { $(this).removeClass('on'); $(this).removeClass('cur'); $(this).find('.child').stop().slideUp(); }else{ $(this).addClass('on').siblings().removeClass('on'); $(this).addClass('cur').siblings().removeClass('cur'); $(this).find('.child').stop().slideDown().parent('li').siblings('li').find('.child').stop().slideUp(); } }) $('.header .nav ul li').hover(function(){ $(this).find('.child').stop().fadeIn().parent().siblings().find('.child').stop().fadeOut(); },function(){ $(this).find('.child').stop().fadeOut(); }) // $('body,html').css({'height':$(window).height(),'width':$(window).width()}); // $(window).resize(function(){ // $('body').css({'height':$(window).height(),'width':$(window).width()}); // }) $('.base-footer .max-box .box i').on('click',function(){ $('.base-footer').fadeOut(); }) $('.footer .left .tit').on('click',function(){ $('.base-footer').fadeIn(); }) $('.footer .icons .sina').hover(function(){ $('.footer .icons .sina .ewm').stop().fadeToggle(); }) $('.footer .icons .wx').hover(function(){ $('.footer .icons .wx .ewm').stop().fadeToggle(); }) $('header .tel').click(function(){ $('.search-box').stop().slideDown(); }) $('.search-box .point').click(function(){ $('.search-box').stop().slideUp(); }) $(window).scroll(function(){ if ($(window).scrollTop()>0) { $(".header").addClass("active"); }else{ $(".header").removeClass("active"); } }) }); function scrollAni() { $('.anim_emt').each(function() { var _this = $(this); if (_this.offset().top > $(window).scrollTop() + $(window).height() || _this.offset().top < $(window).scrollTop() - _this.outerHeight()) { // _this.removeClass('start'); } else if ($(window).scrollTop() > _this.offset().top - $(window).height() * 0.95) { _this.addClass('start visb'); } }); $(window).scroll(function() { $('.anim_emt').each(function() { var _this = $(this); if (_this.offset().top > $(window).scrollTop() + $(window).height() || _this.offset().top < $(window).scrollTop() - _this.outerHeight()) { // _this.removeClass('start'); } else if ($(window).scrollTop() > _this.offset().top - $(window).height() * 0.95) { _this.addClass('start visb'); // $(_this) // startScramble('.i-img-list.animate .home-dec'); } }); }); } scrollAni(); /* var _id = getUrlParam("id"); if (_id == 6) { alert(0); } */ function getUrlParam(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r!=null) return unescape(r[2]); return null; } function MoveBalls(element, opts) { var canvas = document.querySelector(element); this.canvas = canvas; this.ctx = canvas.getContext("2d"); var defaultOpts = { total: 100, color: "#000", size: 6, width: this.canvas.parentNode.clientWidth, height: this.canvas.parentNode.clientHeight }; var opts = opts || defaultOpts; for (var key in opts) { defaultOpts[key] = opts[key]; }; for (var key in defaultOpts) { this[key] = defaultOpts[key]; }; opts = null; defaultOpts = null; // 榧犳爣鍧愭爣 this.coordinate = { x: null, y: null, max: 100 }; // 绮掑瓙 this.dots = []; // 鍚紶鏍囧潗鏍囩殑绮掑瓙鏁扮粍 this.newDots = []; // 鎬绘暟 this.count = 0; // requestAnimationFrame鍏煎澶勭悊 window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60); }; this.colorReg = /[rgba()]/g; this.init(); }; MoveBalls.prototype = { constructor: MoveBalls, init: function () { var _this = this; this.freshResize(); this.mouseEvent(); this.getDots(); var timer = setTimeout(function () { clearTimeout(timer); _this.draw(_this) }, 300); }, colorCheck: function () { this.canvas.style.color = this.color; var colorData = this.canvas.style.color; return colorData = colorData.replace(this.colorReg, "").split(","); }, resize: function (self) { var _this = self || this; _this.canvas.width = _this.width; _this.canvas.height = _this.height; }, freshResize: function () { this.resize(); var _this = this; window.addEventListener("resize", function () { _this.resize(_this); }); }, mouseEvent: function () { var _this = this; _this.canvas.addEventListener("mousemove", function (e) { var e = e || winodw.event; _this.coordinate.x = e.offsetX ? e.offsetX : e.layerX; _this.coordinate.y = e.offsetY ? e.offsetY : e.layerY; }); _this.canvas.addEventListener("mouseout", function () { _this.coordinate.x = null; _this.coordinate.y = null; }) }, getDots: function () { while(this.count < this.total) { var x = Math.random() * this.canvas.width; var y = Math.random() * this.canvas.height; var xMove = Math.random() * 2 - 1; var yMove = Math.random() * 2 - 1; this.dots.push({ x: x, y: y, xMove: xMove, yMove: yMove, max: 100 }); this.count ++; } }, draw: function (self) { var _this = self || this; var ctx = _this.ctx; ctx.clearRect(0, 0, _this.canvas.width, _this.canvas.height); _this.newDots = [_this.coordinate].concat(_this.dots); _this.dots.forEach(function (dot) { dot.xMove *= (dot.x > _this.canvas.width || dot.x < 0) ? -1 : 1; dot.yMove *= (dot.y > _this.canvas.height || dot.y < 0) ? -1 : 1; dot.x += dot.xMove; dot.y += dot.yMove; // 缁樺埗鐐 ctx.save(); ctx.beginPath(); ctx.arc(dot.x, dot.y, _this.size, 0, Math.PI * 5); ctx.fillStyle = _this.color; ctx.fill(); ctx.restore(); // 寰幆姣斿绮掑瓙闂寸殑璺濈 for (var i = 0; i < _this.newDots.length; i ++) { var newDot = _this.newDots[i]; // 濡傛灉鏄涓€涓偣锛屽垯璺宠繃 if(newDot === dot || newDot.x === null || newDot.y === null) continue; var xDistance = dot.x - newDot.x; var yDistance = dot.y - newDot.y; var distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2)); // 棰滆壊娣卞害 var deep = 0; // 灏忎簬鏈€灏忚窛绂伙紝鍒欒繛绾 if (distance <= newDot.max) { // 闄勮繎鐨勫皬鐞冨悜榧犳爣浣嶇疆绉诲姩 if(newDot === _this.coordinate && distance > (newDot.max / 2)) { dot.x -= xDistance * 0.05; dot.y -= yDistance * 0.05; } // 璺濈瓒婅繎---鍊艰秺澶?--棰滆壊瓒婃繁 deep = (newDot.max - distance) / newDot.max; // 鐢荤嚎 ctx.save(); ctx.beginPath(); ctx.lineWidth = deep / 2; var colorInfo = _this.colorCheck(); ctx.strokeStyle = "rgba(" + colorInfo[0] + ", " + colorInfo[1] + ", " + colorInfo[2] + "," + (deep + 0.4) + ")"; ctx.moveTo(dot.x, dot.y); ctx.lineTo(newDot.x, newDot.y); ctx.stroke(); ctx.restore(); } } // 灏嗗凡缁忚绠楄繃鐨勭矑瀛愬垹闄わ紝鍑忓皯閬嶅巻鐨勬€绘暟閲 _this.newDots.splice(_this.newDots.indexOf(dot), 1); }); window.requestAnimationFrame(function (obj) { _this.draw(_this); }); } } if ($("#cs").length>=1) { var moveBalls = new MoveBalls("#cs", {total: 40, color: "#434649", size: 4}); }