::: در حال بارگیری لطفا صبر کنید :::Loading , please wait ...

انجمن کدستانMoisrex

MoisrexMoisrex.rozblog.com
زمان جاریtime : سه شنبه 10 آذر 1405 - 2:45 بعد از ظهر
نام کاربریusername : پسوردpassword : یاor عضویتregister | رمز عبور را فراموش کردمForgot your password?
شما در سایت ما ثبت نام نکرده اید و یا وارد اکانت کاربری خود نشده اید. از شما خواهشمند هستیم You are not log in to site. Please وارد شویدlogin یاor ثبت نام کنیدregister .
mohsen15 آفلاین



ارسال‌هاAsnwers : 93
عضویتRegistration date : 3 /8 /1391
تعداد اخطارWarnings : -2
حمایت کردهthanks : 80
حمایت شدهThanked : 26
پاسخAnswer 29 : این کد عجیب و غریب رو چه جوری نوشتن؟(حتما بببین)

نقل قول از mhmk

کد:
<style>body { margin: 0; }span { position: absolute; top: 15px; left: 5px; color: white; font: 12px Arial;} </style>

<script> // We really want to disable window.open = function() {}; window.alert = function() {}; window.print = function() {}; window.prompt = function() {}; window.confirm = function() {}; </script>

<script> // #killanim is only being used in lab full view, maybe we could // use it everywhere :D//if (window !== window.top && window.top.__stop_animations !== false) {if (window !== window.top && location.hash !== '#dontkillanim') { window.is_webkit = /(webkit)[ /]([w.]+)/.exec(window.navigator.userAgent.toLowerCase())

window.max_timer = window.is_webkit ? 2000 : 20

// Let's try to prevent user's from OOM'ing esp. in FX and Op. // First, we need to stop CSS Animations, after say 5s ? // // Ok, so i tried 5s, but there are some problems. Firstly, Firefox // and opera behave same. little improvement only. So making it 3s now. // // Tutorial: https://developer.mozilla.org/en/CSS/CSS_animations // Help: http://www.sitepoint.com/css3-animation-javascript-event-handlers

var pauseCSSAnimations = function() {

var stopCSSAnimations = function() { // Get the Body Element var body = document.getElementsByTagName('body')[0];

// We'll setup animationstart and animationiteration // events only. No need for animationend, cuz the // animation might be 30minutes long. animationiteration // cuz the animation might be .000002ms long.

// addEventListener is perfectly supported in IE9. // and we don't care about IE8 and below. Let those // browsers die in a fire!

body.addEventListener('webkitAnimationStart', stopAnimation, false); body.addEventListener('webkitAnimationIteration', stopAnimation, false); body.addEventListener('animationstart', stopAnimation, false); body.addEventListener('animationiteration', stopAnimation, false); };

// e is the event object bro ;) var stopAnimation = function(e) { // e.srcElement? lulz... var target_el = e.target; var e_type = e.type.toLowerCase(); if (e_type.indexOf('animationstart') !== -1 || e_type.indexOf('animationiteration') !== -1) { // LOL, we need to stop the animation now! // setInterval? lulz...

setTimeout(false, function() {

if (target_el.style.webkitAnimationPlayState !== 'paused') target_el.style.webkitAnimationPlayState = 'paused';

if (target_el.style.MozAnimationPlayState !== 'paused') target_el.style.MozAnimationPlayState = 'paused';

if (target_el.style.animationPlayState !== 'paused') target_el.style.animationPlayState = 'paused';

}, window.max_timer); } }

stopCSSAnimations();

};

// Next we need to pause/stop JS Animations

var pauseJSAnimations = function() {

// We need to override setInterval, setTimeout // in such a way, that all the calls register their // ids in an array and we can clear all the ids // after a given time. // // Don't trust me ? Lern2Google: // http://stackoverflow.com/a/11374151/1437328 // http://stackoverflow.com/a/8524313/1437328 // http://stackoverflow.com/a/8769620/1437328 // // 3rd one is pretty much the code you need! // // Thank you for building your trust in me now :D

window.setInterval = (function(oldSetInterval) { var registered = [];

var f = function() { var id; // .. this! var $this = this; // setInterval accepts n no. of args var args = arguments; // What if someone used the awesome Function.bind() ? // I am sure we want the awesome apply() then ;)

// this is my awesome brain usage. if first val is nonsense, // then don't register, heh. if (typeof args[0] !== 'function' && args[0] === false) { args = Array.prototype.slice.call(arguments); args = args.slice(1);

id = oldSetInterval.apply($this, args) } else { id = oldSetInterval.apply($this, args); registered.push(id); }

//console.log(registered); // Need to return the Interval ID return id; };

f.clearAll = function() { var r; while (r = registered.pop()) { clearInterval(r); } };

return f; })(window.setInterval);

window.setTimeout = (function(oldSetTimeout) { var registered = [];

var f = function() { var id; // .. this! var $this = this; // setInterval accepts n no. of args var args = arguments; // What if someone used the awesome Function.bind? // I am sure we want the awesome apply then ;)

// this is my awesome brain usage. if first val is nonsense, // then don't register, heh. if (typeof args[0] !== 'function' && args[0] === false) { args = Array.prototype.slice.call(arguments); args = args.slice(1);

id = oldSetTimeout.apply($this, args) } else { //console.log('lolzzzzz'); id = oldSetTimeout.apply($this, args); registered.push(id); }

//console.log(registered); // Need to return the Timeout ID return id; };

f.clearAll = function() { var r; while (r = registered.pop()) { clearTimeout(r); } };

return f; })(window.setTimeout);

setTimeout(false, function() { setTimeout.clearAll(); setInterval.clearAll(); }, window.max_timer);

// Time to Cancel rAF's Bro :) // You know things are harder when people are actually // using shims for rAF :/ So we need to test for vendors!

window.__requestAnimFrame = window.requestAnimationFrame || undefined; window.__cancelAnimFrame = window.cancelAnimationFrame || undefined; window.__vendors = ['webkit', 'moz', 'ms', 'o']; window.__registered_rafs = [];

// I can't think of a good way to cancel rAF's // So maybe lets use something similar to our other canceller's

window.__requestFrame = function(cb) { if (!window.__requestAnimFrame) return;

var req_id = window.__requestAnimFrame(cb); __registered_rafs.push(req_id);

return req_id; };

// Determine the proper VendorPrefixedFunctionName if (!window.__requestAnimFrame) { for (var x = 0; x < window.__vendors.length; x++) { if (!window.__requestAnimFrame) { window.__requestAnimFrame = window[window.__vendors[x]+'RequestAnimationFrame']; window[window.__vendors[x]+'RequestAnimationFrame'] = __requestFrame; }

if(!window.__cancelAnimFrame) { // I came across webkitCancelAnimationFrame and webkitCancelRequestAnimationFrame // No idea about the difference, so maybe lets ||'fy it

window.__cancelAnimFrame = window[window.__vendors[x]+'CancelAnimationFrame'] || window[window.__vendors[x]+'CancelRequestAnimationFrame']; } } }

// We have our proper vendor prefixed raf objects now :) // So let's go mad!!! // Let's Cancel our rAF's setTimeout(false, function() { if (!window.__requestAnimFrame) return; var r; while (r = window.__registered_rafs.pop()) { window.__cancelAnimFrame(r); } }, window.max_timer);

};

// Had to place outside pauseAnimations to work properly // else it was getting called afterwards code setTimeout/Interval executed if (window !== window.top) pauseJSAnimations();

var __pauseAnimations = function() { if (window !== window.top) pauseCSSAnimations(); };}else { __pauseAnimations = function() {};} </script></head><body onload="__pauseAnimations();">

<canvas id=c></canvas> <span>Try disturbing the particles with mouse</span><script>

/* Text masked spring particles Author: Kushagra Gour a.k.a. Chin Chang (@chinchang457)*/

(function() { var H, Particle, W, animate, animationLoop, canvas, changeWord, colors, ctx, damping_constant, density, display_list, draw, getTextArray, init, last_time, min_distance, num_particles, onMouseMove, spring_constant, text_array, update;

window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { return window.setTimeout(callback, 1000 / 60); }; })();

canvas = null;

ctx = null;

num_particles = 500;

density = 8;

min_distance = 70;

text_array = [];

display_list = [];

last_time = null;

spring_constant = 0.2;

damping_constant = 0.08;

colors = ['#184DF4', '#F49A03', '#E01730', '#00A415'];

W = window.innerWidth;

H = window.innerHeight;

init = function(e) { var i, _i, _results; canvas = document.getElementById('c'); ctx = canvas.getContext('2d'); canvas.width = W; canvas.height = H; canvas.addEventListener('mousemove', onMouseMove); changeWord('code'); if (text_array.length) { _results = []; for (i = _i = 0; 0 <= num_particles ? _i < num_particles : _i > num_particles; i = 0 <= num_particles ? ++_i : --_i) { _results.push(display_list.push(new Particle)); } return _results; } };

getTextArray = function(ox, oy, w, h) { var data, i, j, linear_index, _i, _j; text_array = []; data = ctx.getImageData(ox, oy, w, h).data; for (i = _i = 0; 0 <= h ? _i < h : _i > h; i = _i += density) { for (j = _j = 0; 0 <= w ? _j < w : _j > w; j = _j += density) { linear_index = (i * w + j) * 4; if (data[linear_index + 3] !== 0) { text_array.push({ x: j, y: i }); } } } return text_array; };

onMouseMove = function(e) { var child, d, dx, dy, mx, my, _i, _len, _results; mx = e.offsetX || e.pageX; my = e.offsetY || e.pageY; _results = []; for (_i = 0, _len = display_list.length; _i < _len; _i++) { child = display_list[_i]; dx = child.x - mx; dy = child.y - my; d = Math.sqrt(dx * dx + dy * dy); if (d < min_distance) { child.speed_x += dx * 0.05; _results.push(child.speed_y += dy * 0.05); } else { _results.push(void 0); } } return _results; };

changeWord = function(str) { var child, _i, _len, _results; ctx.clearRect(0, 0, W, H); ctx.fillStyle = "#000"; ctx.textBaseline = 'top'; ctx.textAlign = 'center'; ctx.font = "200px Arial"; ctx.fillText(str, W / 2, 0); text_array = getTextArray(0, 0, W, H); _results = []; for (_i = 0, _len = display_list.length; _i < _len; _i++) { child = display_list[_i]; _results.push(child.reposition()); } return _results; };

animate = function() { animationLoop(); return requestAnimFrame(animate); };

animationLoop = function() { var current_time, dt; if (!last_time) { last_time = (new Date).getTime(); } current_time = (new Date).getTime(); dt = (current_time - last_time) / 1000; last_time = current_time; window.fps = 1 / dt; draw(); return update(); };

draw = function() { var child, _i, _len, _results; ctx.fillStyle = "#111"; ctx.fillRect(0, 0, W, H); _results = []; for (_i = 0, _len = display_list.length; _i < _len; _i++) { child = display_list[_i]; if (typeof child.draw !== 'function') { continue; } ctx.save(); if (!isNaN(child.x || isNaN(child.y))) { ctx.translate(child.x, child.y); } if (!isNaN(child.scale_x || isNaN(child.scale_y))) { ctx.scale(child.scale_x, child.scale_y); } if (!isNaN(child.alpha)) { ctx.globalAlpha = child.alpha; } child.draw(); _results.push(ctx.restore()); } return _results; };

update = function() { var child, _i, _len, _results; _results = []; for (_i = 0, _len = display_list.length; _i < _len; _i++) { child = display_list[_i]; if (typeof child.update === 'function') { _results.push(child.update()); } else { _results.push(void 0); } } return _results; };

Particle = (function() {

function Particle(radius, x, y) { this.radius = radius != null ? radius : 1; this.x = x != null ? x : Math.random() * W; this.y = y != null ? y : Math.random() * H; this.speed_x = 10 - Math.random() * 20; this.speed_y = 10 - Math.random() * 20; this.color = "#ff0"; this.alpha = 1; this.reposition(); this.reset(); }

Particle.prototype.draw = function() { ctx.fillStyle = this.color; ctx.beginPath(); ctx.arc(4, 4, 4, 0, Math.PI * 2, true); return ctx.fill(); };

Particle.prototype.update = function() { var acc_x, acc_y; acc_x = -spring_constant * (this.x - this.ox) - damping_constant * this.speed_x; acc_y = -spring_constant * (this.y - this.oy) - damping_constant * this.speed_y; this.speed_x += acc_x; this.speed_y += acc_y; this.alpha -= 0.019; this.scale_x += 0.06; this.scale_y += 0.06; this.x += this.speed_x; this.y += this.speed_y; if (this.alpha <= 0) { return this.reset(); } };

Particle.prototype.reset = function() { this.alpha = Math.random(); this.scale_x = this.scale_y = 0; return this.color = colors[~~(Math.random() * colors.length)]; };

Particle.prototype.reposition = function() { var point; point = text_array[~~(Math.random() * text_array.length)]; this.ox = this.x = point.x + ~~(3 + Math.random() * 6); return this.oy = this.y = point.y + ~~(3 + Math.random() * 6); };

return Particle;

})();

init();

animate();

}).call(this);</script>

خیلی جالبه ممنون.





جمعه 06 اردیبهشت 1392 - 13:55
ارسال پیامSend p.m. نقل قولReply سپاس گزارمThanks



moisrex
درباره ماAbout us لینک های ماOur links کلمات کلیدیKeywords
انجمن تخصصی کدستان ، ساخته شده توسط فردی با نام مستعار Moisrex می باشد.This forum designed by a person who called Moisrex.

ایمیلE-mail : Moisrex @ Gmail.com
کدستان,انجمن کدستان,کدنویسی,انجمن پشتیبانی,فروم,رزبلاگ,آموزش کدنویسی,درخواست کد
تمامی حقوق این انجمن مربوط به همین انجمن می باشد | طراحی قالبCopyright (c) By Moisrex , All rights reserved | Desiger : Moisrex