Edge
Hello,

Welcome on the website of "Edge" also known as "edge-pk.com"
i hope you will enjoy your self on the site.
The Edge server was first owned by maarten, he sold it to us for a fair price, now you can enjoy the max of "EDGE".

Good Luck Playing, and please register

A few fun JavaScript/jQuery scripts

Go down

A few fun JavaScript/jQuery scripts

Post  Guest on Mon Mar 22, 2010 9:18 pm

Tag Clouds
Code:
function tagCloud(tags) {
   var maxsize = 44, minsize = 9, tag=new Array(), ta=new Array(), cloud='', h=0, val=0, i=0;
   tags.forEach(function(t){if (tag[t]) {tag[t]++;}else{tag[t]=1;ta[i++]=t;}});
   ta.forEach(function(g){if (tag[g] > h) {h=tag[g];}});val=(maxsize/h);
   ta.forEach(function(r){var s=(Math.round(val*tag[r])>minsize) ? Math.round(val*tag[r]) : minsize;cloud+="<span style='font-size:"+s+"'>"+r+"</span>";});
   return cloud;
}
Takes an array, and displays values that have a higher amount of occurrences with bigger text: Example




Insult Generator
Code:
var n=Array('drink','goat'), p=Array('spinn','grunt');
function gW(t){return(t == 1)?n[Math.floor(Math.random()*n.length)]:p[Math.floor(Math.random()*p.length)];}
function setIns(){
   var f=gW(1), v=(/^[aeiou]/i.test(f)==true)?'an':'a';for(s=gW(1);s==f;s=gW(1));
   document.getElementById('insult').innerText="You're "+v+" "+f+" "+gW()+"ing "+s+" "+gW()+"er.";
}
Possible outputs:
You're a drink grunting goat spinner.
You're a drink spinning goat spinner.
You're a drink grunting goat grunter.
You're a drink spinning goat grunter.

You're a goat grunting drink spinner.
You're a goat spinning drink spinner.
You're a goat grunting drink grunter.
You're a goat spinning drink grunter.
The amount of outputs changes drastically by the amount of gerunds and nouns you input.




jQuery drop down lists
Code:
$('.item').hide();
$('.drop').hover(function(){jQuery('.item',this).animate({'height':'20px','opacity':1},200);},
function(){jQuery('.item',this).animate({'height':'0px','opacity':0},200);});
Speaks for itself, featured on http://left4quake.com/maupin




Pong
Code:

var x = 5;
var y = 5;
var status = 0;
$(document).ready(function(){
   div = $("<div class='ball'>").html("&nbsp;");
   epad = $("<div class='epad'>").html("&nbsp;");
   ppad = $("<div class='ppad'>").html("&nbsp;");
   $("body").prepend(div).prepend(epad).prepend(ppad);
   setTimeout("$('.epad').css({'backgroundColor':'black','position':'absolute'}).animate({'height': 100,'width': 10, 'top':0,'right':10},1000).animate({'top': Math.round($(window).height() / 2 - Math.round($('.epad').height() *3))},1000);$('.ppad').css({'backgroundColor':'black','position':'absolute'}).animate({'height': 100,'width': 10, 'top':0,'left':10},1000).animate({'top': Math.round($(window).height() / 2 - Math.round($('.ppad').height() * 3))},1000);$('.ball').css({'backgroundColor':'black','position':'absolute','height': 10,'width': 10, 'top':0,'left':0}).animate({'top': Math.round($(window).height() / 2 - Math.round($('.ball').height() /2)), 'left':  Math.round($(window).width() / 2 - Math.round($('.ball').width() *3))},2000);",30);
   setTimeout("status = 1; ballMove();",3000);
   $(document).bind("mousemove", changeP);
   function changeP(event) {
      if (status == 1) {
         $('.ppad').css({"top":Math.round(event.pageY - ($('.ppad').height() /2))});
         $(this).css({cursor: 'none'});
      }
   }
});
function ballMove() {
   if (status = 1) {
      eMove();
      var offset = $('.ball').offset();
      var pffset = $('.ppad').offset();
      var effset = $('.epad').offset();
      if (offset.left < 20) {
         if (Math.floor(offset.top - pffset.top) < 100 && Math.floor(offset.top - pffset.top) > 0) {
            x *= -1;
            x += 1;
         }
         if (Math.round(Math.random()) == 1) {
            y -= Math.round(Math.random() * 3);
         }
         else {
            y += Math.round(Math.random() * 3);
         }
      }
      if   (offset.left > Math.round($(window).width() - 30)) {
         if (Math.floor(offset.top - effset.top) < 100 && Math.floor(offset.top - effset.top) > 0) {
            x *= -1;
            x -= 1;
            if (Math.round(Math.random()) == 1) {
               y -= Math.round(Math.random() * 3);
            }
            else {
               y += Math.round(Math.random() * 3);
            }
         }
      }
      if (offset.left < -10 || offset.left > Math.round($(window).width() + 10)) {   
         if (offset.left > 0) {
            return restart(alert('YOU WIN!'));
         }
         else {
            return restart(alert('YOU LOSE'));
         }
      }
      if (offset.top < 0 || offset.top > Math.floor($(window).height() - 15)) {
         y *= -1;
      }
      $('.ball').css({'left':Math.round(offset.left + x),'top':Math.round(offset.top + y)});
   }
   setTimeout('ballMove()',30);
}
function restart() {
   $('.ball').css({'background':'#ccc','border':'solid 1px black'}).animate({'top': Math.round($(window).height() / 2 - Math.round($('.ball').height() /2)), 'left':  Math.round($(window).width() / 2 - Math.round($('.ball').width() *3))},1000);
   if (Math.round(Math.random()) == 1) { x = Math.ceil(Math.random() * -15); }
   else { x = Math.ceil(Math.random() * 15); }
   if (Math.round(Math.random()) == 1) { y = Math.ceil(Math.random() * -15); }
   else { y = Math.ceil(Math.random() * 15); }
   setTimeout('ballMove(); $(".ball").css({"background":"black","border":"none"});',2000);
}
function eMove() {
   var boff = $('.ball').offset();
   var eoff = $('.epad').offset();
   var eoff2 = Math.round(eoff.top + ($('.epad').height() / 2));
   if (boff.top > eoff2) {
      $('.epad').css({'top':Math.round(eoff.top + 7)});
   }
   else if (boff.top < eoff2) {
      $('.epad').css({'top':Math.round(eoff.top - 7)});
   }
}
A fully working pong game.
Live demo: http://left4quake.com/pong.html

Guest
Guest


Back to top Go down

Re: A few fun JavaScript/jQuery scripts

Post  Iwin on Thu Apr 22, 2010 4:04 am

@Pong

The other dude cant lose. It went behind him and came back out.

~Fail =]

Iwin
Junior member
Junior member

Posts : 20
Reputation : 10
Join date : 2010-03-22
Age : 25

View user profile

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum