Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=windows-1251" />
- <meta name="description" content="JQuery tests" />
- <title>JQuery tests</title>
- <script src="jquery.min.js"></script>
- <style type="text/css">
- .sq {
- position:absolute;
- background-color:red;
- width:50px;
- height:50px;
- }
- .sqo {
- background-color:#fa0;
- position:relative;
- border:solid 1px #888;
- float:left;
- margin:5px;
- }
- .sqz {
- width:200px;
- height:200px;
- border:solid 1px red;
- }
- .bgz {
- position:absolute;
- width:200px;
- height:200px;
- background-color:#f5f5f5;
- border:solid 1px #aaa;
- z-index:300;
- padding:25px;
- }
- .lsq {
- width:50px;
- height:50px;
- border:solid 1px #888;
- background-color:#eee;
- float:left;
- margin:4px;
- cursor:pointer;
- }
- .uuu {
- width:200px;
- height:100px;
- border:solid 1px #777;
- background-color:#f5f5f5;
- position:absolute;
- padding:10px;
- }
- </style>
- <script type="text/javascript">
- function ra(x) {
- return Math.floor(Math.random()*x);
- }
- function rgbr() {
- return 'rgb('+ra(255)+','+ra(255)+','+ra(255)+')';
- }
- //-----------------------------------------------------
- function mktabs() {
- var b=$(document.body);
- b.append($('<div/>', {'class':'bgz'}).css({'left':100, 'top':400}));
- b.append($('<div/>', {'class':'bgz'}).css({'left':400, 'top':400}));
- $('.bgz:first').append($('<table/>',
- {cellspacing:"0",
- cellpadding: "8",
- border: "1",
- bordercolor: "#aaa"
- }));
- tab = $('.bgz:first').children(':first').get(0);
- var sect = tab.tBodies[0] && tab.tBodies[tab.tBodies.length-1] || tab;
- for (var i=0; i<5; i++) {
- var row = sect.insertRow(i);
- for (var j=0; j<5; j++) {
- var cell= row.insertCell(j);
- cell.innerHTML=i+'<sup>'+j+'</sup>';
- }
- }
- var tabd = $('table[bordercolor="#aaa"] td');
- tabd.css('cursor','pointer');
- tabd.hover(function(ev) {
- var curel=$(this);
- var currow = $(this).parent();
- //-----------------------------
- $(this).parent().parent().find('td[rel!="inff"]').filter(
- function(index) {
- return $(this).parent().get(0)!==currow.get(0);
- }
- ).css('background-color','');
- //-----------------------------
- $(this).parent().children('td[rel!="inff"]').filter(
- function(index) {
- return $(this).get(0)!=curel.get(0)
- }
- ).css('background-color','#fee');
- $(this).css('background-color','white');
- });
- tabd.click(function(ev) {
- $(this).css({display:'block', 'position':'absolute'})
- .attr('rel','inff')
- .css({left: $(this).position().left,
- top: $(this).position().top})
- .animate({
- 'left': '+='+ra(100),
- 'top': '+='+ra(100)},"slow");
- });
- //----------------------------------
- // form
- //----------------------------------
- el = $('.bgz:empty');
- el.append($('<form/>').append($('<fieldset/>')
- .append($('<legend/>').text('checks'))
- .append($('<p/>').text('New York')
- .append($('<input/>',{type:'checkbox',
- name:'city[]',
- value:'NY'})))
- .append($('<p/>').text('London')
- .append($('<input/>', {type:'checkbox',
- name: 'city[]',
- value:'london'})))
- .append($('<p/>').text('Tokio')
- .append($('<input/>', {type:'checkbox',
- name: 'city[]',
- value:'tokio'})))));
- el.find('form input[type="checkbox"]').change(
- function(ev) {
- var actEl = this;
- if ($(this).attr('checked')!==undefined) {
- els = $(this).parent().parent().find('input[type="checkbox"]')
- els.each ( function(index,ele) {
- //alert($(ele).attr('value'));
- //alert(index);
- if ($(this).get(0)!==actEl) {
- $(this).removeAttr('checked');
- }
- })
- }
- }
- )
- }
- //-----------------------------------------------------
- function init_anim() {
- glMX=0;
- glMY=0;
- mktabs();
- $(document).mousemove(
- function(ev) {
- glMX = ev.clientX + document.documentElement.scrollLeft;
- glMY = ev.clientY + document.documentElement.scrollTop;
- }
- )
- //-----------------------------------------
- var el = $('<div>',{class:'sq', id:'element-1'});
- function fireworks() {
- for(var i=0; i<20; i++) {
- $(this).clone().css({
- 'left':$(this).position().left,
- 'top':$(this).position().top})
- .appendTo(document.body)
- .animate({'left':'-='+ra(2000), 'top':'-='+ra(2000), 'opacity':0},
- ra(3000))
- .queue( function() {
- $(this).remove();
- });
- }
- $(this).dequeue();
- }
- //-------------------------------
- el.hover(
- function(ev) {
- var newX = $(this).position().left+ra(200);
- var newY = $(this).position().top + ra(200);
- $(this).css('background-color',rgbr())
- .queue( fireworks)
- .animate({'left': newX,
- 'top': newY},
- 500);
- var cent=false;
- if ((newX>window.innerWidth) || (newX<0)) {
- newX = Math.floor(window.innerWidth/2);
- cent=true;
- }
- if ((newY>window.innerHeight) || (newY<0)) {
- newY = Math.floor(window.innerHeight/2);
- cent=true;
- }
- if (cent===true) {
- $(this).animate({'left':newX, 'top':newY});
- }
- },
- function(ev) {
- $(this).queue( function() {
- var newX=$(this).position().left-ra(200);
- var newY=$(this).position().top-ra(200);
- $(this).css('background-color', rgbr())
- .delay(500).queue(fireworks).animate({
- 'left': newX,
- 'top': newY},
- 500);
- var cent=false;
- if ((newX>window.innerWidth) || (newX<0)) {
- newX = Math.floor(window.innerWidth/2);
- cent=true;
- }
- if ((newY>window.innerHeight) || (newY<0)) {
- newY = Math.floor(window.innerHeight/2);
- cent=true;
- }
- if (cent===true) {
- $(this).animate({'left':newX, 'top':newY});
- }
- $(this).dequeue();
- }
- );
- })
- glInt = setInterval(movelbox, 8000);
- //----------------------------------------
- function movelbox() {
- var el = $('#element-1').parent();
- var x = el.position().left;
- var y = el.position().top;
- if (el.queue('fx').length>10)
- el.clearQueue();
- el.animate({left:glMX-100, top:glMY-100}, "slow");
- }
- var b = $(document.body);
- b.append(el);
- var z = el.clone();
- b.append(z);
- z.css('background-color','green');
- $('.sq:first').animate({
- left: Math.floor($(document).width()/2),
- top: Math.floor($(document).height()/2)
- });
- $.when(z.animate({'left':'100', 'top':'100'}, 'slow')).done (
- function() {
- z.wrap('<div/>');
- z.parent().addClass('sqz').css('position','absolute')
- .css({'z-index':100,'background-color':'#f5f5f5'})
- /*.append(
- $('.sq:first').animate({'opacity':0.5},"slow"))*/
- .animate({left: 800, top: 400}, "slow")
- .bind('mouseover', function(ev){
- ev.stopPropagation();
- if ($(this).data('busy')===true)
- return true;
- $(this).data('busy',true);
- if (!($(this).data('wd')))
- $(this).data('wd',$(this).width());
- $(this).css({'background-color': 'rgb(255,200,200)'})
- .animate({width:'50',height:'50'},"slow")
- .animate({width: $(this).data('wd'), height: $(this).data('wd')})
- .queue(
- function() {
- $(this).css('background-color', '#eee');
- $(this).data('busy', false);
- $(this).dequeue();
- });
- })
- .bind('mousedown', function(ev) {
- ev.preventDefault();
- $(this).data('pressed',true);
- $(this).data('difx',
- ev.clientX+document.documentElement.scrollLeft-
- $(this).offset().left);
- $(this).data('dify',
- ev.clientY+document.documentElement.scrollTop-
- $(this).position().top);
- })
- .bind('mouseup', function (ev) {
- $(this).data('pressed',false);
- })
- .bind('mouseout', function(ev) {
- $(this).trigger('mouseup');
- })
- .bind('mousemove', function(ev) {
- if ($(this).data('pressed')===true) {
- $(this).css('left',
- ev.clientX -$(this).data('difx'));
- $(this).css('top', ev.clientY - $(this).data('dify'));
- }
- })
- } );
- var t = $('<input>', {type:'text', name:'posinf'});
- b.append(t);
- //--------------------------------------------
- var move_func = function (ev) {
- var elinf = $('input[name="posinf"]');
- elinf.attr('value', ev.pageX+'-'+ev.pageY+'-'+ev.clientX+'-'+ev.clientY);
- }
- $(document).bind('mousemove', move_func)
- //---------------------------------------------
- b3 = $(document.createElement('DIV'));
- b3.prependTo(b);
- ani3=false;
- b3.css({'border':'solid 1px #888',
- 'position':'absolute'}).animate({'left':screen.width/3,
- 'top':screen.height/4,
- 'width':'400', 'height':'200'},400, complete_ani);
- //---------------------------------------------
- function complete_ani() {
- ani3=true;
- }
- setTimeout(next_step,1000);
- //---------------------------------------------
- $('div:last').after('<div/>');
- el=$('div:last');
- el.addClass('sqz').css('position','absolute').animate
- ({left: document.documentElement.clientWidth/5,
- top:document.documentElement.clientHeight/4});
- var ff = $('<div>',{class:'lsq'});
- for (var i=0; i<9; i++) {
- ff.clone().appendTo(el).append($('<div>', {style:'padding:20px'}))
- .children().first().text(i+1)
- .end().end().click( {inf:i+1}, click3);
- }
- //-------------------------------------------
- function click3(ev) {
- addsibl = function() {
- var sibl= $(this).after($('<div/>').addClass($(this).attr('class'))
- .append($(this).contents().clone())
- .on('click',arguments.callee)
- .on('mouseover',
- function(ev) {
- $(this).fadeOut('slow');
- })
- .css({'background-color': '#fee'})
- );
- $(this).dequeue();
- }
- $(this).fadeOut("slow").fadeIn("slow").queue(addsibl);
- //---------------------------------
- var a= $('<div class="uuu"/>').hide().appendTo(document.body);
- a.append($('<p/>').text(ev.data.inf));
- p=a.find('p:first');
- p.after($('<p/>').text('mousekey'+ev.which));
- a.css({left:600, top:10}).toggle("slow").delay(1000)
- .slideToggle(1000, function() {$(this).remove()});
- }
- }
- //---------------------------------------------
- //---------------------------------------------
- function next_step() {
- if (!ani3) {
- setTimeout(arguments.callee,1000);
- return;
- }
- click4 = function(ev) {
- ev = ev || event;
- t = ev.target;
- for (var i=0; i<20; i++) {
- var z = $(t).clone().css({'position':'absolute',
- 'top':$(t).offset().top,
- 'left':$(t).offset().left})
- .appendTo($(document.body));
- z.delay(ra(500)).animate({left:'-='+ra(2000), top:'-='+ra(2000)},ra(3000))
- .queue( function() {$(this).remove();})
- //.end().clone().delay(400).animate({left:200, top:300},500)
- // .queue( function() {$(this).remove();});
- }
- }
- //---------------------------------------------
- for (i=0; i<5; i++) {
- b3.append($('<div/>'));
- }
- b3.children('div').addClass('sq sqo').each(
- function(j){
- $(this).bind('click',{inf4:j+1},
- function(ev) {click4(ev);});});
- $('div[style*="solid"]').children().filter(':eq(0)').css('background-color','red')
- .end().filter(':gt(3)').css('background-color','#fa8')
- .end().filter(':nth-child(3)').css('background-color','green')
- .end().filter(':eq(1)').add('div[style*="solid"] div:eq(3)').fadeOut("slow")
- .fadeIn("slow")
- .slideUp("slow")
- .slideDown("slow").fadeTo('slow',0.5, next3_step);
- }
- //---------------------------------------------
- function next3_step() {
- var els = $('div[style*="solid"]').children();
- els.fadeToggle("slow").fadeToggle("slow")
- .hide('400')
- .show(500)
- }
- $(document).ready(init_anim);
- </script>
- </head>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement