How to use ypos method in wpt

Best JavaScript code snippet using wpt

myscript_org.js

Source:myscript_org.js Github

copy

Full Screen

1$(document).ready(function() {2 var divTemp = document.getElementById("divNums");3 for (var i = 8; i >= 1; i--) {4 divTemp.innerHTML = divTemp.innerHTML + "<div style='line-height:65px;'>" + i + "</div>";5 }6 var divTemp = document.getElementById("divChars");7 var charArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];8 for (var i = 1; i <= 8; i++) {9 divTemp.innerHTML = divTemp.innerHTML + "<span style='width:65px;display:inline-block;text-align:center'>" + charArray[i - 1] + "</span>";10 }11 12});13$(function() {14 // Initializing chess board15 setDefaultAttributes4Boxes();16 setDefaultAttributes4Symbols();17 $("div.box").mousedown(function() {18 var curX = $(this).attr("XPos");19 var curY = $(this).attr("YPos");20 var tmpChessSymbols = $(".chessSymbols");21 var bInit = true;22 for (var i = 0; i < tmpChessSymbols.length; i++) {23 if ($(tmpChessSymbols[i]).attr("XPos") === curX) {24 if ($(tmpChessSymbols[i]).attr("YPos") === curY) {25 bInit = false;26 break;27 }28 }29 }30 if (bInit) {31 initializeBoxes();32 }33 });34 $(".chessSymbols").mousedown(function() {35 initializeBoxes();36 calculateDPath(this);37 colorOwn(this);38 $("div.higlightedBoxes").droppable({39 drop: function(event, ui) {40 //$("div.higlightedBoxes").droppable('destroy');41 }42 });43 $("div.enemyBoxes").droppable({44 drop: function(event, ui) {45 //$("div.higlightedBoxes").droppable('destroy');46 }47 }); 48 });49 $(".chessSymbols").mouseup(function() {50 $(this).draggable({51 revert: function(obj) {52 if (obj) {53 // Let's change the child54 var tmpBoxes = $("div.box");55 var child = null;56 for (var i = 0; i < tmpBoxes.length; i++) {57 // Find the previous box who owns the child and detach the child58 var curXPos = $(this).attr("XPos");59 var curYPos = $(this).attr("YPos");60 if ($(tmpBoxes[i]).attr("XPos") === curXPos) {61 if ($(tmpBoxes[i]).attr("YPos") === curYPos) {62 child = $(tmpBoxes[i]).children().detach();63 break;64 }65 }66 }67 for (var i = 0; i < tmpBoxes.length; i++) {68 // Find the new box who owns the child and atach the child69 var curXPos = $(obj).attr("XPos");70 var curYPos = $(obj).attr("YPos");71 if ($(tmpBoxes[i]).attr("XPos") === curXPos) {72 if ($(tmpBoxes[i]).attr("YPos") === curYPos) {73 if ($(tmpBoxes[i]).hasClass('enemyBoxes')){74 $(tmpBoxes[i]).children().fadeOut(1000);75 setTimeout(function(){76 $(tmpBoxes[i]).children().detach(); 77 $(child).css('left', 0);78 $(child).css('top', 0);79 $(tmpBoxes[i]).prepend(child); 80 },1000);81 82 }else{83 $(child).css('left', 0);84 $(child).css('top', 0);85 $(tmpBoxes[i]).prepend(child);86 }87 break;88 }89 }90 }91 // Let's set new positions92 $(this).attr("XPos", $(obj).attr("XPos"));93 $(this).attr("YPos", $(obj).attr("YPos"));94 $(this).draggable('destroy');95 initializeBoxes();96 return false;97 }98 return true;99 }100 }101 );102 });103 $("div.box").hover(function() {104 //console.log("(" + $(this).attr("XPos") + "," + $(this).attr("YPos") + ")") ;105 });106});107function setDefaultAttributes4Symbols() {108 /* Here are the attributes and thier propable values,109 * 1. Symbol type = {ROOK, KNIGHT, BISHOP, KING, QUEEN, PAWN}110 * 2. Team = {Black, White}111 * 3. XPos = {a,b,c,d,e,f,g,h}112 * 4. YPos = {1,2,3,4,5,6,7,8}113 * */114 // Black team115 //******************************************************************116 var divTemp = $("#div8 div .chessSymbols");117 for (var i = 1; i <= divTemp.length; i++) {118 // For rooks119 if ((i === 1) || (i === 8)) {120 if (i === 1) {121 $(divTemp[i - 1]).attr({122 Type: "ROOK",123 Team: "BLACK",124 XPos: "a",125 YPos: 8126 });127 } else {128 $(divTemp[i - 1]).attr({129 Type: "ROOK",130 Team: "BLACK",131 XPos: "h",132 YPos: 8133 });134 }135 }136 // For knights137 else if ((i === 2) || (i === 7)) {138 if (i === 2) {139 $(divTemp[i - 1]).attr({140 Type: "KNIGHT",141 Team: "BLACK",142 XPos: "b",143 YPos: 8144 });145 } else {146 $(divTemp[i - 1]).attr({147 Type: "KNIGHT",148 Team: "BLACK",149 XPos: "g",150 YPos: 8151 });152 }153 }154 // For bishops155 else if ((i === 3) || (i === 6)) {156 if (i === 3) {157 $(divTemp[i - 1]).attr({158 Type: "BISHOP",159 Team: "BLACK",160 XPos: "c",161 YPos: 8162 });163 } else {164 $(divTemp[i - 1]).attr({165 Type: "BISHOP",166 Team: "BLACK",167 XPos: "f",168 YPos: 8169 });170 }171 }172 // For queen173 else if (i === 4) {174 $(divTemp[i - 1]).attr({175 Type: "QUEEN",176 Team: "BLACK",177 XPos: "d",178 YPos: 8179 });180 }181 // For king182 else {183 $(divTemp[i - 1]).attr({184 Type: "KING",185 Team: "BLACK",186 XPos: "e",187 YPos: 8188 });189 }190 }191 divTemp = $("#div7 div .chessSymbols");192 for (var i = 1; i <= divTemp.length; i++) {193 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];194 $(divTemp[i - 1]).attr({195 Type: "PAWN",196 Team: "BLACK",197 XPos: xPosS[i - 1],198 YPos: 7199 });200 }201 // White team202 //******************************************************************203 divTemp = $("#div1 div .chessSymbols");204 for (var i = 1; i <= divTemp.length; i++) {205 // For rooks206 if ((i === 1) || (i === 8)) {207 if (i === 1) {208 $(divTemp[i - 1]).attr({209 Type: "ROOK",210 Team: "WHITE",211 XPos: "a",212 YPos: 1213 });214 } else {215 $(divTemp[i - 1]).attr({216 Type: "ROOK",217 Team: "WHITE",218 XPos: "h",219 YPos: 1220 });221 }222 }223 // For knights224 else if ((i === 2) || (i === 7)) {225 if (i === 2) {226 $(divTemp[i - 1]).attr({227 Type: "KNIGHT",228 Team: "WHITE",229 XPos: "b",230 YPos: 1231 });232 } else {233 $(divTemp[i - 1]).attr({234 Type: "KNIGHT",235 Team: "WHITE",236 XPos: "g",237 YPos: 1238 });239 }240 }241 // For bishops242 else if ((i === 3) || (i === 6)) {243 if (i === 3) {244 $(divTemp[i - 1]).attr({245 Type: "BISHOP",246 Team: "WHITE",247 XPos: "c",248 YPos: 1249 });250 } else {251 $(divTemp[i - 1]).attr({252 Type: "BISHOP",253 Team: "WHITE",254 XPos: "f",255 YPos: 1256 });257 }258 }259 // For queen260 else if (i === 4) {261 $(divTemp[i - 1]).attr({262 Type: "QUEEN",263 Team: "WHITE",264 XPos: "d",265 YPos: 1266 });267 }268 // For king269 else {270 $(divTemp[i - 1]).attr({271 Type: "KING",272 Team: "WHITE",273 XPos: "e",274 YPos: 1275 });276 }277 }278 divTemp = $("#div2 div .chessSymbols");279 for (var i = 1; i <= divTemp.length; i++) {280 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];281 $(divTemp[i - 1]).attr({282 Type: "PAWN",283 Team: "WHITE",284 XPos: xPosS[i - 1],285 YPos: 2286 });287 }288}289function setDefaultAttributes4Boxes() {290 /* Here are the attributes and thier propable values,291 * 1. XPos = {a,b,c,d,e,f,g,h}292 * 2. YPos = {1,2,3,4,5,6,7,8}293 * */294 for (var i = 1; i <= 8; i++) {295 var divTemp = $("#div" + i + " div.box");296 for (var j = 0; j < divTemp.length; j++) {297 var xPosS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];298 $(divTemp[j]).attr({299 XPos: xPosS[j],300 YPos: i301 });302 }303 }304}305function calculateDPath(chessSymbol) {306 /* This is the process of this method.307 * Major is calculating the path of a chess symbol.308 * 1. Identify the symbol type309 * 2. Get it's current location on the board.310 * 3. Calculating the paths, "where it can go"311 * I. When finding the path search for blocks312 * II. Color where the paths are313 * III.Color the enemy boxes314 */315 if ($(chessSymbol).attr("Type") === "ROOK") {316 // Where is he now? (curXPos,curYPos)317 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));318 var curYPos = parseInt($(chessSymbol).attr("YPos"));319 // Let's find out where he can go320 if ((curXPos - 1) !== 0) {321 for (var i = curXPos - 1; i > 0; i--) {322 var reObj = isHereSomeone(i, curYPos);323 if (reObj.is) {324 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {325 colorMe(i, curYPos, true);326 }327 break;328 }329 colorMe(i, curYPos, false);330 }331 for (var i = curXPos + 1; i <= 8; i++) {332 var reObj = isHereSomeone(i, curYPos);333 if (reObj.is) {334 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {335 colorMe(i, curYPos, true);336 }337 break;338 }339 colorMe(i, curYPos, false);340 }341 } else {342 for (var i = 2; i <= 8; i++) {343 var reObj = isHereSomeone(i, curYPos);344 if (reObj.is) {345 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {346 colorMe(i, curYPos, true);347 }348 break;349 }350 colorMe(i, curYPos, false);351 }352 }353 if ((curYPos - 1) !== 0) {354 for (var i = curYPos - 1; i > 0; i--) {355 var reObj = isHereSomeone(curXPos, i);356 if (reObj.is) {357 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {358 colorMe(curXPos, i, true);359 }360 break;361 }362 colorMe(curXPos, i, false);363 }364 for (var i = (curYPos + 1); i <= 8; i++) {365 var reObj = isHereSomeone(curXPos, i);366 if (reObj.is) {367 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {368 colorMe(curXPos, i, true);369 }370 break;371 }372 colorMe(curXPos, i, false);373 }374 } else {375 for (var i = 2; i <= 8; i++) {376 var reObj = isHereSomeone(curXPos, i);377 if (reObj.is) {378 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {379 colorMe(curXPos, i, true);380 }381 break;382 }383 colorMe(curXPos, i, false);384 }385 }386 }387 else if ($(chessSymbol).attr("Type") === "KNIGHT") {388 // Where is he now? (curXPos,curYPos)389 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));390 var curYPos = parseInt($(chessSymbol).attr("YPos"));391 // Logic #1392 if (curXPos - 2 > 0) {393 if (curYPos + 1 < 9) {394 var reObj = isHereSomeone(curXPos - 2, curYPos + 1);395 if (reObj.is) {396 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {397 colorMe(curXPos - 2, curYPos + 1, true);398 }399 } else {400 colorMe(curXPos - 2, curYPos + 1, false);401 }402 }403 if (curYPos - 1 > 0) {404 var reObj = isHereSomeone(curXPos - 2, curYPos - 1);405 if (reObj.is) {406 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {407 colorMe(curXPos - 2, curYPos - 1, true);408 }409 } else {410 colorMe(curXPos - 2, curYPos - 1, false);411 }412 }413 }414 // Logic #2415 if (curXPos + 2 > 0) {416 if (curYPos + 1 < 9) {417 var reObj = isHereSomeone(curXPos + 2, curYPos + 1);418 if (reObj.is) {419 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {420 colorMe(curXPos + 2, curYPos + 1, true);421 }422 } else {423 colorMe(curXPos + 2, curYPos + 1, false);424 }425 }426 if (curYPos - 1 > 0) {427 var reObj = isHereSomeone(curXPos + 2, curYPos - 1);428 if (reObj.is) {429 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {430 colorMe(curXPos + 2, curYPos - 1, true);431 }432 } else {433 colorMe(curXPos + 2, curYPos - 1, false);434 }435 }436 }437 // Logic #3438 if (curYPos - 2 > 0) {439 if (curXPos + 1 < 9) {440 var reObj = isHereSomeone(curXPos + 1, curYPos - 2);441 if (reObj.is) {442 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {443 colorMe(curXPos + 1, curYPos - 2, true);444 }445 } else {446 colorMe(curXPos + 1, curYPos - 2, false);447 }448 }449 if (curXPos - 1 > 0) {450 var reObj = isHereSomeone(curXPos - 1, curYPos - 2);451 if (reObj.is) {452 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {453 colorMe(curXPos - 1, curYPos - 2, true);454 }455 } else {456 colorMe(curXPos - 1, curYPos - 2, false);457 }458 }459 }460 // Logic #4461 if (curYPos + 2 > 0) {462 if (curXPos + 1 < 9) {463 var reObj = isHereSomeone(curXPos + 1, curYPos + 2);464 if (reObj.is) {465 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {466 colorMe(curXPos + 1, curYPos + 2, true);467 }468 } else {469 colorMe(curXPos + 1, curYPos + 2, false);470 }471 }472 if (curXPos - 1 > 0) {473 var reObj = isHereSomeone(curXPos - 1, curYPos + 2);474 if (reObj.is) {475 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {476 colorMe(curXPos - 1, curYPos + 2, true);477 }478 } else {479 colorMe(curXPos - 1, curYPos + 2, false);480 }481 }482 }483 }484 else if ($(chessSymbol).attr("Type") === "BISHOP") {485 // Where is he now? (curXPos,curYPos)486 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));487 var curYPos = parseInt($(chessSymbol).attr("YPos"));488 // Between [0-90] degrees489 var tmpYPos = curYPos;490 for (var x = curXPos + 1; x <= 8; x++) {491 tmpYPos++;492 if (tmpYPos > 8)493 break;494 var reObj = isHereSomeone(x, tmpYPos);495 if (reObj.is) {496 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {497 colorMe(x, tmpYPos, true);498 }499 break;500 } else {501 colorMe(x, tmpYPos, false);502 }503 }504 // Between [90-180] degrees505 tmpYPos = curYPos;506 for (var x = curXPos - 1; x >= 1; x--) {507 tmpYPos++;508 if (tmpYPos > 8)509 break;510 var reObj = isHereSomeone(x, tmpYPos);511 if (reObj.is) {512 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {513 colorMe(x, tmpYPos, true);514 }515 break;516 } else {517 colorMe(x, tmpYPos, false);518 }519 }520 // Between [180-270] degrees521 tmpYPos = curYPos;522 for (var x = curXPos - 1; x >= 1; x--) {523 tmpYPos--;524 if (tmpYPos < 1)525 break;526 var reObj = isHereSomeone(x, tmpYPos);527 if (reObj.is) {528 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {529 colorMe(x, tmpYPos, true);530 }531 break;532 } else {533 colorMe(x, tmpYPos, false);534 }535 }536 // Between [270-360] degrees537 tmpYPos = curYPos;538 for (var x = curXPos + 1; x <= 8; x++) {539 tmpYPos--;540 if (tmpYPos < 1)541 break;542 var reObj = isHereSomeone(x, tmpYPos);543 if (reObj.is) {544 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {545 colorMe(x, tmpYPos, true);546 }547 break;548 } else {549 colorMe(x, tmpYPos, false);550 }551 }552 }553 else if ($(chessSymbol).attr("Type") === "QUEEN") {554 // Where is she now? (curXPos,curYPos)555 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));556 var curYPos = parseInt($(chessSymbol).attr("YPos"));557 // Queen has rook qualities558 if ((curXPos - 1) !== 0) {559 for (var i = curXPos - 1; i > 0; i--) {560 var reObj = isHereSomeone(i, curYPos);561 if (reObj.is) {562 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {563 colorMe(i, curYPos, true);564 }565 break;566 }567 colorMe(i, curYPos, false);568 }569 for (var i = curXPos + 1; i <= 8; i++) {570 var reObj = isHereSomeone(i, curYPos);571 if (reObj.is) {572 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {573 colorMe(i, curYPos, true);574 }575 break;576 }577 colorMe(i, curYPos, false);578 }579 } else {580 for (var i = 2; i <= 8; i++) {581 var reObj = isHereSomeone(i, curYPos);582 if (reObj.is) {583 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {584 colorMe(i, curYPos, true);585 }586 break;587 }588 colorMe(i, curYPos, false);589 }590 }591 if ((curYPos - 1) !== 0) {592 for (var i = curYPos - 1; i > 0; i--) {593 var reObj = isHereSomeone(curXPos, i);594 if (reObj.is) {595 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {596 colorMe(curXPos, i, true);597 }598 break;599 }600 colorMe(curXPos, i, false);601 }602 for (var i = (curYPos + 1); i <= 8; i++) {603 var reObj = isHereSomeone(curXPos, i);604 if (reObj.is) {605 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {606 colorMe(curXPos, i, true);607 }608 break;609 }610 colorMe(curXPos, i, false);611 }612 } else {613 for (var i = 2; i <= 8; i++) {614 var reObj = isHereSomeone(curXPos, i);615 if (reObj.is) {616 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {617 colorMe(curXPos, i, true);618 }619 break;620 }621 colorMe(curXPos, i, false);622 }623 }624 // ------------------------------------------------------------------------------625 // Queen has bishop qualities626 // Between [0-90] degrees627 var tmpYPos = curYPos;628 for (var x = curXPos + 1; x <= 8; x++) {629 tmpYPos++;630 if (tmpYPos > 8)631 break;632 var reObj = isHereSomeone(x, tmpYPos);633 if (reObj.is) {634 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {635 colorMe(x, tmpYPos, true);636 }637 break;638 } else {639 colorMe(x, tmpYPos, false);640 }641 }642 // Between [90-180] degrees643 tmpYPos = curYPos;644 for (var x = curXPos - 1; x >= 1; x--) {645 tmpYPos++;646 if (tmpYPos > 8)647 break;648 var reObj = isHereSomeone(x, tmpYPos);649 if (reObj.is) {650 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {651 colorMe(x, tmpYPos, true);652 }653 break;654 } else {655 colorMe(x, tmpYPos, false);656 }657 }658 // Between [180-270] degrees659 tmpYPos = curYPos;660 for (var x = curXPos - 1; x >= 1; x--) {661 tmpYPos--;662 if (tmpYPos < 1)663 break;664 var reObj = isHereSomeone(x, tmpYPos);665 if (reObj.is) {666 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {667 colorMe(x, tmpYPos, true);668 }669 break;670 } else {671 colorMe(x, tmpYPos, false);672 }673 }674 // Between [270-360] degrees675 tmpYPos = curYPos;676 for (var x = curXPos + 1; x <= 8; x++) {677 tmpYPos--;678 if (tmpYPos < 1)679 break;680 var reObj = isHereSomeone(x, tmpYPos);681 if (reObj.is) {682 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {683 colorMe(x, tmpYPos, true);684 }685 break;686 } else {687 colorMe(x, tmpYPos, false);688 }689 }690 }691 else if ($(chessSymbol).attr("Type") === "KING") {692 // Where is he now? (curXPos,curYPos)693 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));694 var curYPos = parseInt($(chessSymbol).attr("YPos"));695 // #Logic 1 in current X position696 if (curYPos + 1 < 9) {697 var reObj = isHereSomeone(curXPos, curYPos + 1);698 if (reObj.is) {699 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {700 colorMe(curXPos, curYPos + 1, true);701 }702 } else {703 colorMe(curXPos, curYPos + 1, false);704 }705 }706 if (curYPos - 1 > 0) {707 var reObj = isHereSomeone(curXPos, curYPos - 1);708 if (reObj.is) {709 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {710 colorMe(curXPos, curYPos - 1, true);711 }712 } else {713 colorMe(curXPos, curYPos - 1, false);714 }715 }716 // #Logic 2 in (current X + 1) position717 if (curXPos + 1 < 9) {718 // Case 1: current Y719 var reObj = isHereSomeone(curXPos + 1, curYPos);720 if (reObj.is) {721 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {722 colorMe(curXPos + 1, curYPos, true);723 }724 } else {725 colorMe(curXPos + 1, curYPos, false);726 }727 // Case 2: (current Y + 1)728 reObj = isHereSomeone(curXPos + 1, curYPos + 1);729 if (reObj.is) {730 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {731 colorMe(curXPos + 1, curYPos + 1, true);732 }733 } else {734 colorMe(curXPos + 1, curYPos + 1, false);735 }736 // Case 3: (current Y - 1)737 reObj = isHereSomeone(curXPos + 1, curYPos - 1);738 if (reObj.is) {739 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {740 colorMe(curXPos + 1, curYPos - 1, true);741 }742 } else {743 colorMe(curXPos + 1, curYPos - 1, false);744 }745 }746 // #Logic 3 in (current X - 1) position747 if (curXPos + 1 < 9) {748 // Case 1: current Y749 var reObj = isHereSomeone(curXPos - 1, curYPos);750 if (reObj.is) {751 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {752 colorMe(curXPos - 1, curYPos, true);753 }754 } else {755 colorMe(curXPos - 1, curYPos, false);756 }757 // Case 2: (current Y + 1)758 reObj = isHereSomeone(curXPos - 1, curYPos + 1);759 if (reObj.is) {760 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {761 colorMe(curXPos - 1, curYPos + 1, true);762 }763 } else {764 colorMe(curXPos - 1, curYPos + 1, false);765 }766 // Case 3: (current Y - 1)767 reObj = isHereSomeone(curXPos - 1, curYPos - 1);768 if (reObj.is) {769 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {770 colorMe(curXPos - 1, curYPos - 1, true);771 }772 } else {773 colorMe(curXPos - 1, curYPos - 1, false);774 }775 }776 }777 else {778 // Where is he now? (curXPos,curYPos)779 var curXPos = convertRealXPos($(chessSymbol).attr("XPos"));780 var curYPos = parseInt($(chessSymbol).attr("YPos"));781 if (curYPos + 1 < 9) {782 if ($(chessSymbol).attr("Team") === "WHITE") {783 var reObj = isHereSomeone(curXPos, curYPos + 1);784 if (!reObj.is) {785 colorMe(curXPos, curYPos + 1, false);786 if (curYPos === 2) {787 reObj = isHereSomeone(curXPos, curYPos + 2);788 if (!reObj.is) {789 colorMe(curXPos, curYPos + 2, false);790 }791 }792 }793 }794 if (curXPos - 1 > 0) {795 reObj = isHereSomeone(curXPos - 1, curYPos + 1);796 if (reObj.is) {797 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {798 colorMe(curXPos - 1, curYPos + 1, true);799 }800 }801 }802 if (curXPos + 1 < 9) {803 reObj = isHereSomeone(curXPos + 1, curYPos + 1);804 if (reObj.is) {805 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {806 colorMe(curXPos + 1, curYPos + 1, true);807 }808 }809 }810 }811 if (curYPos - 1 > 0) {812 if ($(chessSymbol).attr("Team") === "BLACK") {813 var reObj = isHereSomeone(curXPos, curYPos - 1);814 if (!reObj.is) {815 colorMe(curXPos, curYPos - 1, false);816 if (curYPos === 7) {817 reObj = isHereSomeone(curXPos, curYPos - 2);818 if (!reObj.is) {819 colorMe(curXPos, curYPos - 2, false);820 }821 }822 }823 }824 if (curXPos - 1 > 0) {825 reObj = isHereSomeone(curXPos - 1, curYPos - 1);826 if (reObj.is) {827 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {828 colorMe(curXPos - 1, curYPos - 1, true);829 }830 }831 }832 if (curXPos + 1 < 9) {833 reObj = isHereSomeone(curXPos + 1, curYPos - 1);834 if (reObj.is) {835 if ($(reObj.who).attr("Team") !== $(chessSymbol).attr("Team")) {836 colorMe(curXPos + 1, curYPos - 1, true);837 }838 }839 }840 }841 }842}843function convertRealXPos(charXPos) {844 switch (charXPos) {845 case "a":846 {847 return 1;848 break;849 }850 case "b":851 {852 return 2;853 break;854 }855 case "c":856 {857 return 3;858 break;859 }860 case "d":861 {862 return 4;863 break;864 }865 case "e":866 {867 return 5;868 break;869 }870 case "f":871 {872 return 6;873 break;874 }875 case "g":876 {877 return 7;878 break;879 }880 case "h":881 {882 return 8;883 break;884 }885 }886}887function isHereSomeone(xPos, yPos) {888 var chessSymbols = $(".chessSymbols");889 var returnObject = new Object();890 returnObject.who = null;891 returnObject.is = false;892 for (var i = 0; i < chessSymbols.length; i++) {893 if ((convertRealXPos($(chessSymbols[i]).attr("XPos")) === xPos) &&894 (parseInt($(chessSymbols[i]).attr("YPos")) === yPos)) {895 returnObject.is = true;896 returnObject.who = $(chessSymbols[i]);897 return returnObject;898 }899 }900 return returnObject;901}902function initializeBoxes() {903 $("div.higlightedBoxes").droppable('destroy');904 $("div.enemyBoxes").droppable('destroy');905 var divBoxes = $(".higlightedBoxes");906 for (var i = 0; i < divBoxes.length; i++) {907 $(divBoxes[i]).removeClass("higlightedBoxes");908 }909 divBoxes = $(".enemyBoxes");910 for (var i = 0; i < divBoxes.length; i++) {911 $(divBoxes[i]).removeClass("enemyBoxes");912 }913 divBoxes = $(".colorOwnBox");914 for (var i = 0; i < divBoxes.length; i++) {915 $(divBoxes[i]).removeClass("colorOwnBox");916 } 917}918function colorMe(xPos, yPos, enemy) {919 var divName = "#div" + yPos + " div.box";920 var divBoxes = $(divName);921 for (var i = 0; i < divBoxes.length; i++) {922 if ((i + 1) === xPos) {923 if (!enemy) {924 $(divBoxes[i]).addClass("higlightedBoxes");925 } else {926 $(divBoxes[i]).addClass("enemyBoxes");927 }928 break;929 }930 }931}932function colorOwn(Me) {933 // Where am I now? (curXPos,curYPos)934 var curXPos = convertRealXPos($(Me).attr("XPos"));935 var curYPos = parseInt($(Me).attr("YPos"));936 var divName = "#div" + curYPos + " div.box";937 var divBoxes = $(divName);938 for (var i = 0; i < divBoxes.length; i++) {939 if ((i + 1) === curXPos) {940 $(divBoxes[i]).addClass("colorOwnBox");941 break;942 }943 }...

Full Screen

Full Screen

Alphabet.js

Source:Alphabet.js Github

copy

Full Screen

1function colors(){2 palettebluepink = [3 color(248, 73, 41), //red4 color(69, 97, 220), //blue5 color(59, 50, 89), //drk blue6 color(251, 151, 162), //pink7 color(201, 208, 234), //light blue8 color(240, 206, 181), //tan9 color(81, 216, 236),10 color(61, 77, 191) //drk blue11 ]12}13//------A-----------14function LetterA(xPos, yPos) {15 this.xPos = xPos;16 this.yPos = yPos;17 push();18 translate(this.xPos, this.yPos);19 noFill();20 strokeWeight(letterstroke);21 stroke(palettebluepink[1]);22 line(letterwidth / 2, 0, 0, letterheight);23 stroke(palettebluepink[6]);24 line(letterwidth / 2, 0, letterwidth, letterheight);25 stroke(palettebluepink[5]);26 line(letterwidth * .26, letterxheight, letterwidth * .66, letterxheight); //crossbar27 pop();28}29//-----B-------30function LetterB(xPos, yPos) {31 this.xPos = xPos;32 this.yPos = yPos;33 push();34 translate(this.xPos, this.yPos);35 noFill();36 strokeWeight(letterstroke);37 stroke(palettebluepink[2]);38 line(0, 0, 0, letterheight); //left39 stroke(palettebluepink[0]);40 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //top round41 stroke(palettebluepink[4]);42 rect(0, letterxheight, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //bottom round43 pop();44}45//-----C---------46function LetterC(xPos, yPos) { //define arguments and then use them inside the function to be updated in draw47 this.xPos = xPos;48 this.yPos = yPos;49 push();50 translate(this.xPos, this.yPos);51 ellipseMode(CENTER);52 noFill();53 strokeWeight(letterstroke);54 angleMode(DEGREES);55 stroke(palettebluepink[6]);56 arc(letterwidth / 2, letterheight / 2.5, letterwidth, letterheight * .8, 180, 350);57 stroke(palettebluepink[0]);58 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);59 stroke(palettebluepink[2]);60 line(0, letterheight * .4, 0, letterheight * .6); //left straight line61 strokeWeight(letterstrokeB);62 stroke(240, 90);63 angleMode(DEGREES);64 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //G65 pop();66}67//---------D--------68function LetterD(xPos, yPos) {69 this.xPos = xPos;70 this.yPos = yPos;71 push();72 translate(this.xPos, this.yPos);73 noFill();74 strokeWeight(letterstroke);75 stroke(palettebluepink[5]);76 rect(0, 0, letterwidth, letterheight, 0, letterrounding, letterrounding, 0);77 pop();78}79//-----E-------80function LetterE(xPos, yPos) {81 this.xPos = xPos;82 this.yPos = yPos;83 push();84 translate(this.xPos, this.yPos);85 noFill();86 strokeWeight(letterstroke);87 stroke(palettebluepink[5]);88 line(0, 0, 0, letterheight);89 stroke(palettebluepink[6]);90 line(0, letterheight, letterwidth, letterheight); //bottom91 stroke(palettebluepink[3]);92 line(0, 0, letterwidth, 0); //top93 stroke(palettebluepink[2]);94 line(0, letterxheight, letterwidth, letterxheight); //center95 strokeWeight(letterstrokeB);96 stroke(240, 90);97 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N98 pop();99}100//-----F-------101function LetterF(xPos, yPos) {102 this.xPos = xPos;103 this.yPos = yPos;104 push();105 translate(this.xPos, this.yPos);106 noFill();107 strokeWeight(letterstroke);108 stroke(palettebluepink[1]);109 line(0, 0, 0, letterheight);110 stroke(palettebluepink[0]);111 line(0, 0, letterwidth, 0); //top bar112 stroke(palettebluepink[3]);113 line(0, letterxheight, letterwidth, letterxheight); //bottombar114 pop();115}116//-----G---------117function LetterG(xPos, yPos) {118 this.xPos = xPos;119 this.yPos = yPos;120 push();121 translate(this.xPos, this.yPos);122 noFill();123 strokeWeight(letterstroke);124 stroke(palettebluepink[1]);125 angleMode(DEGREES);126 arc(letterwidth / 2, letterheight / 2.5, letterwidth, letterheight * .8, 180, 350);127 stroke(palettebluepink[2]);128 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);129 stroke(palettebluepink[7]);130 line(letterwidth / 2, letterxheight, letterwidth, letterxheight); //cross line131 stroke(palettebluepink[4]);132 line(0,letterheight * .45, 0, letterheight * .55); //left straight line133 pop();134}135//-----H-------136function LetterH(xPos, yPos) {137 this.xPos = xPos;138 this.yPos = yPos;139 push();140 translate(this.xPos, this.yPos);141 noFill();142 strokeWeight(letterstroke);143 stroke(palettebluepink[5]);144 line(0, 0, 0, letterheight); //left145 stroke(palettebluepink[6]);146 line(0, letterxheight, letterwidth, letterxheight); //top bar147 stroke(palettebluepink[1]);148 line(letterwidth, 0, letterwidth, letterheight); //right149 strokeWeight(letterstrokeB);150 stroke(240, 90);151 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N152 pop();153}154//-----I-------155function LetterI(xPos, yPos) {156 this.xPos = xPos;157 this.yPos = yPos;158 push();159 translate(this.xPos, this.yPos);160 noFill();161 strokeWeight(letterstroke);162 stroke(palettebluepink[6]);163 line(0, 0, letterwidth, 0); //top164 line(0, letterheight, letterwidth, letterheight); //bottom165 stroke(palettebluepink[3]);166 line(letterwidth / 2, 0, letterwidth / 2, letterheight); //long167 stroke(palettebluepink[2]);168 // line(0, letterxheight, letterwidth, letterxheight); //center169 // strokeWeight(letterstrokeB);170 // stroke(240, 90);171 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N172 pop();173}174//-----J-------175function LetterJ(xPos, yPos) {176 this.xPos = xPos;177 this.yPos = yPos;178 push();179 translate(this.xPos, this.yPos);180 noFill();181 strokeWeight(letterstroke);182 stroke(palettebluepink[6]);183 line(0, 0, letterwidth, 0); //top184 stroke(palettebluepink[4]);185 // arc(0, letterxheight, letterwidth, letterxheight, PI + (QUARTER_PI / 3), OPEN);186 angleMode(DEGREES);187 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);188 stroke(palettebluepink[3]);189 line(letterwidth, 0, letterwidth, letterxheight); //long190 stroke(palettebluepink[2]);191 pop();192}193//-----K-------194function LetterK(xPos, yPos) {195 this.xPos = xPos;196 this.yPos = yPos;197 push();198 translate(this.xPos, this.yPos);199 noFill();200 strokeWeight(letterstroke);201 stroke(palettebluepink[6]);202 line(0, 0, 0, letterheight); //left203 stroke(palettebluepink[7]);204 line(0, letterxheight, letterwidth, 0); //towards top205 stroke(palettebluepink[0]);206 line(letterwidth * .5, letterheight*.4, letterwidth, letterheight); //bottom207 pop();208}209//-----L-------210function LetterL(xPos, yPos) {211 this.xPos = xPos;212 this.yPos = yPos;213 push();214 translate(this.xPos, this.yPos);215 noFill();216 strokeWeight(letterstroke);217 stroke(palettebluepink[5]);218 line(0, 0, 0, letterheight);219 stroke(palettebluepink[6]);220 line(0, letterheight, letterwidth, letterheight); //top bar221 strokeWeight(letterstrokeB);222 stroke(240, 90);223 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N224 pop();225}226//------M-----227function LetterM(xPos, yPos) {228 this.xPos = xPos;229 this.yPos = yPos;230 push();231 translate(this.xPos, this.yPos);232 noFill();233 strokeWeight(letterstroke);234 stroke(palettebluepink[0]);235 line(0, 0, 0, letterheight); //left236 stroke(palettebluepink[2]);237 line(0, 0, letterwidth * .6, letterxheight); //across bottom left238 stroke(palettebluepink[5]);239 line(letterwidth, 0, letterwidth, letterheight); //right240 stroke(palettebluepink[3]);241 line(letterwidth, 0, letterwidth * .4, letterxheight); //across bottom left242 // strokeWeight(letterstrokeB);243 // stroke(240, 90);244 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N245 pop();246}247//------N-----248function LetterN(xPos, yPos) {249 this.xPos = xPos;250 this.yPos = yPos;251 push();252 translate(this.xPos, this.yPos);253 noFill();254 strokeWeight(letterstroke);255 stroke(palettebluepink[5]);256 line(0, 0, 0, letterheight);257 stroke(palettebluepink[0]);258 line(0, 0, letterwidth, letterheight);259 stroke(palettebluepink[2]);260 line(letterwidth, 0, letterwidth, letterheight);261 strokeWeight(letterstrokeB);262 stroke(240, 90);263 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N264 pop();265}266//------O------267function LetterO(xPos, yPos) {268 this.xPos = xPos;269 this.yPos = yPos;270 push();271 translate(this.xPos, this.yPos);272 rectMode(CORNER);273 ellipseMode(CENTER);274 noFill();275 strokeWeight(letterstroke);276 stroke(palettebluepink[5]);277 rect(0, 0, letterwidth, letterheight, letterrounding, letterrounding, letterrounding, letterrounding);278 strokeWeight(letterstrokeB);279 stroke(240, 90);280 angleMode(DEGREES);281 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //O282 pop();283}284//-----P-------285function LetterP(xPos, yPos) {286 this.xPos = xPos;287 this.yPos = yPos;288 push();289 translate(this.xPos, this.yPos);290 noFill();291 strokeWeight(letterstroke);292 stroke(palettebluepink[2]);293 line(0, 0, 0, letterheight); //left294 stroke(palettebluepink[0]);295 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0);296 // line(0, letterxheight, letterwidth, letterxheight); //top bar297 // line(letterwidth, 0, letterwidth, letterheight); //right298 // strokeWeight(letterstrokeB);299 // stroke(240, 90);300 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N301 pop();302}303//------Q------304function LetterQ(xPos, yPos) {305 this.xPos = xPos;306 this.yPos = yPos;307 push();308 translate(this.xPos, this.yPos);309 rectMode(CORNER);310 ellipseMode(CENTER);311 noFill();312 strokeWeight(letterstroke);313 stroke(palettebluepink[5]);314 rect(0, 0, letterwidth, letterheight, letterrounding, letterrounding, letterrounding, letterrounding);315 stroke(palettebluepink[0]);316 line(letterwidth / 2, letterxheight, letterwidth, letterheight);317 strokeWeight(letterstrokeB);318 stroke(240, 90);319 angleMode(DEGREES);320 arc(letterwidth / 2, letterheight / 3, letterwidth / 1.7, letterwidth / 1.7, 180, 360); //O321 pop();322}323//-----R-------324function LetterR(xPos, yPos) {325 this.xPos = xPos;326 this.yPos = yPos;327 push();328 translate(this.xPos, this.yPos);329 noFill();330 strokeWeight(letterstroke);331 stroke(palettebluepink[6]);332 line(0, 0, 0, letterheight); //left333 stroke(palettebluepink[7]);334 rect(0, 0, letterwidth, letterxheight, 0, letterrounding, letterrounding, 0); //rounded335 stroke(palettebluepink[0]);336 line(letterwidth * .7, letterxheight, letterwidth, letterheight);337 // line(0, letterxheight, letterwidth, letterxheight); //top bar338 // line(letterwidth, 0, letterwidth, letterheight); //right339 // strokeWeight(letterstrokeB);340 // stroke(240, 90);341 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N342 pop();343}344//-----S-------345function LetterS(xPos, yPos) {346 this.xPos = xPos;347 this.yPos = yPos;348 push();349 translate(this.xPos, this.yPos);350 noFill();351 strokeWeight(letterstroke);352 stroke(palettebluepink[2]);353 bezier(letterwidth, 0, 0, 0, letterwidth, letterheight, 0, letterheight); //temporary354 pop();355}356//-----T-------357function LetterT(xPos, yPos) {358 this.xPos = xPos;359 this.yPos = yPos;360 push();361 translate(this.xPos, this.yPos);362 noFill();363 strokeWeight(letterstroke);364 stroke(palettebluepink[6]);365 line(0, 0, letterwidth, 0); //top366 stroke(palettebluepink[6]);367 // line(0, letterheight, letterwidth, letterheight); //bottom368 stroke(palettebluepink[3]);369 line(letterwidth / 2, 0, letterwidth / 2, letterheight); //long370 stroke(palettebluepink[2]);371 // line(0, letterxheight, letterwidth, letterxheight); //center372 // strokeWeight(letterstrokeB);373 // stroke(240, 90);374 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight * .8); //N375 pop();376}377//------U-----------378function LetterU(xPos, yPos) {379 this.xPos = xPos;380 this.yPos = yPos;381 push();382 translate(this.xPos, this.yPos);383 noFill();384 strokeWeight(letterstroke);385 stroke(palettebluepink[6]);386 line(0, 0, 0, letterxheight);387 stroke(palettebluepink[1]);388 line(letterwidth, 0, letterwidth, letterxheight);389 stroke(palettebluepink[0]);390 angleMode(DEGREES);391 stroke(palettebluepink[4]);392 arc(letterwidth / 2, letterheight - letterheight / 2.5, letterwidth, letterheight * .8, 360, 180);393 pop();394}395//------V-----------396function LetterV(xPos, yPos) {397 this.xPos = xPos;398 this.yPos = yPos;399 push();400 translate(this.xPos, this.yPos);401 noFill();402 strokeWeight(letterstroke);403 stroke(palettebluepink[6]);404 line(letterwidth / 2, letterheight, 0, 0);405 stroke(palettebluepink[1]);406 line(letterwidth / 2, letterheight, letterwidth, 0);407 pop();408}409//------W-----410function LetterW(xPos, yPos) {411 this.xPos = xPos;412 this.yPos = yPos;413 push();414 translate(this.xPos, this.yPos);415 noFill();416 strokeWeight(letterstroke);417 stroke(palettebluepink[0]);418 line(0, 0, 0, letterheight); //left419 stroke(palettebluepink[2]);420 line(0, letterheight, letterwidth * .6, letterxheight); //across bottom left421 stroke(palettebluepink[5]);422 line(letterwidth, 0, letterwidth, letterheight); //right423 stroke(palettebluepink[3]);424 line(letterwidth, letterheight, letterwidth * .4, letterxheight); //across bottom left425 // strokeWeight(letterstrokeB);426 // stroke(240, 90);427 // line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N428 pop();429}430//------X-----431function LetterX(xPos, yPos) {432 this.xPos = xPos;433 this.yPos = yPos;434 push();435 translate(this.xPos, this.yPos);436 noFill();437 strokeWeight(letterstroke);438 stroke(palettebluepink[5]);439 line(letterwidth, 0, 0, letterheight);440 stroke(palettebluepink[0]);441 line(0, 0, letterwidth, letterheight);442 stroke(palettebluepink[2]);443 strokeWeight(letterstrokeB);444 stroke(240, 90);445 line(letterwidth / 5, 0 + letterheight / 3, letterwidth / 5, letterheight); //N446 pop();447}448//-----Y---------449function LetterY(xPos, yPos) {450 this.xPos = xPos;451 this.yPos = yPos;452 push();453 translate(this.xPos, this.yPos);454 noFill();455 strokeWeight(letterstroke);456 stroke(palettebluepink[0]);457 angleMode(DEGREES);458 459 arc(letterwidth / 2, 0, letterwidth, letterheight * .8, 360,180);460 stroke(palettebluepink[1]);461 line(letterwidth / 2, letterheight, letterwidth / 2,letterheight * .4); //left straight line462 pop();463}464//-----Z-------465function LetterZ(xPos, yPos) {466 this.xPos = xPos;467 this.yPos = yPos;468 push();469 translate(this.xPos, this.yPos);470 noFill();471 strokeWeight(letterstroke);472 stroke(palettebluepink[6]);473 line(0, 0, letterwidth, 0); //top474 stroke(palettebluepink[2]);475 line(0, letterheight, letterwidth, letterheight); //bottom476 stroke(palettebluepink[3]);477 line(letterwidth, 0,0,letterheight); //across478 pop();...

Full Screen

Full Screen

nav.js

Source:nav.js Github

copy

Full Screen

1//Nav Scroll234$(window).scroll(function(){5 var scrollYpos= $(document).scrollTop();6 var h=$(window).height();7 var d=0;8 9 if (scrollYpos >=h*0+d && scrollYpos <h*1+d) {10 $('#nav1').css('opacity', .4);11 }12 else {13 $('#nav1').css('opacity', 1);14 }15 if (scrollYpos >=h*1+d && scrollYpos <h*2+d) {16 $('#nav2').css('opacity', .4);17 }18 else {19 $('#nav2').css('opacity', 1);20 }21 if (scrollYpos >=h*2+d && scrollYpos <h*3+d) {22 $('#nav3').css('opacity', .4);23 }24 else {25 $('#nav3').css('opacity', 1);26 }27 if (scrollYpos >=h*3+d && scrollYpos <h*4+d) {28 $('#nav4').css('opacity', .4);29 }30 else {31 $('#nav4').css('opacity', 1);32 }33 if (scrollYpos >=h*4+d && scrollYpos <h*5+d) {34 $('#nav5').css('opacity', .4);35 }36 else {37 $('#nav5').css('opacity', 1);38 }39 if (scrollYpos >=h*5+d && scrollYpos <h*6+d) {40 $('#nav6').css('opacity', .4);41 }42 else {43 $('#nav6').css('opacity', 1);44 }45 if (scrollYpos >=h*6+d && scrollYpos <h*7+d) {46 $('#nav7').css('opacity', .4);47 }48 else {49 $('#nav7').css('opacity', 1);50 }51 if (scrollYpos >=h*7+d && scrollYpos <h*8+d) {52 $('#nav8').css('opacity', .4);53 }54 else {55 $('#nav8').css('opacity', 1);56 }57 if (scrollYpos >=h*8+d && scrollYpos <h*9+d) {58 $('#nav9').css('opacity', .4);59 }60 else {61 $('#nav9').css('opacity', 1);62 }63 if (scrollYpos >=h*9+d && scrollYpos <h*10+d) {64 $('#nav10').css('opacity', .4);65 }66 else {67 $('#nav10').css('opacity', 1);68 }69 if (scrollYpos >=h*10+d && scrollYpos <h*11+d) {70 $('#nav11').css('opacity', .4);71 }72 else {73 $('#nav11').css('opacity', 1);74 }75 if (scrollYpos >=h*11+d && scrollYpos <h*12+d) {76 $('#nav12').css('opacity', .4);77 }78 else {79 $('#nav12').css('opacity', 1);80 }81 if (scrollYpos >=h*12+d && scrollYpos <h*13+d) {82 $('#nav13').css('opacity', .4);83 }84 else {85 $('#nav13').css('opacity', 1);86 }87 if (scrollYpos >=h*13+d && scrollYpos <h*14+d) {88 $('#nav14').css('opacity', .4);89 }90 else {91 $('#nav14').css('opacity', 1);92 }93 if (scrollYpos >=h*14+d && scrollYpos <h*15+d) {94 $('#nav15').css('opacity', .4);95 }96 else {97 $('#nav15').css('opacity', 1);98 }99 if (scrollYpos >=h*15+d && scrollYpos <h*16+d) {100 $('#nav16').css('opacity', .4);101 }102 else {103 $('#nav16').css('opacity', 1);104 }105 if (scrollYpos >=h*16+d && scrollYpos <h*17+d) {106 $('#nav17').css('opacity', .4);107 }108 else {109 $('#nav17').css('opacity', 1);110 }111 if (scrollYpos >=h*17+d && scrollYpos <h*18+d) {112 $('#nav18').css('opacity', .4);113 }114 else {115 $('#nav18').css('opacity', 1);116 }117 if (scrollYpos >=h*18+d && scrollYpos <h*19+d) {118 $('#nav19').css('opacity', .4);119 }120 else {121 $('#nav19').css('opacity', 1);122 }123})124125$(document).ready(function(){126 $('#navspot').localScroll(800);127})128129$(document).ready(function(){130 $('#logo').localScroll(800); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest')('www.webpagetest.org');2wpt.runTest(url, {3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test submitted to WebPagetest for %s', url);6 console.log('Test ID: %s', data.data.testId);7 var testId = data.data.testId;8 wpt.getTestStatus(testId, function(err, data) {9 if (err) return console.error(err);10 console.log('Test status for %s: %s', testId, data.data.statusText);11 console.log('Test completed in %d seconds', data.data.completedIn);12 wpt.getTestResults(testId, function(err, data) {13 if (err) return console.error(err);14 console.log('Test results for %s:', testId);15 console.log(data.data.median);16 });17 });18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3var params = {4};5client.runTest(url, params, function(err, data) {6 if (err) return console.error(err);7 console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("wpt");2wpt.ypos(function(err, data) {3 console.log(data);4});5### `wpt.ypos(callback)`6### `wpt.xpos(callback)`7### `wpt.size(callback)`8### `wpt.maximize(callback)`9### `wpt.minimize(callback)`10### `wpt.restore(callback)`11### `wpt.close(callback)`12### `wpt.setposition(x, y, callback)`13### `wpt.setsize(width, height, callback)`14### `wpt.setsizeandposition(width, height, x, y, callback)`15### `wpt.setpositionandsize(x, y, width, height, callback)`16### `wpt.refresh(callback)`17### `wpt.back(callback)`18### `wpt.forward(callback)`19### `wpt.geturl(callback)`20### `wpt.gettitle(callback)`21### `wpt.gethtml(callback)`22### `wpt.getcookies(callback)`23### `wpt.getheaders(callback)`24### `wpt.getsource(callback)`25### `wpt.gettext(callback)`26### `wpt.getbody(callback)`27### `wpt.getbodytext(callback)`28### `wpt.getstatus(callback)`29### `wpt.getstatuscode(callback)`30### `wpt.getstatusmessage(callback)`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('A.5b7c5e5e5b7c5e5e5b7c5e5e5b7c5e5e');3var options = {4 videoParams: {5 }6};7client.runTest(url, options, function (err, data) {8 if (err) return console.error(err);9 console.log('Test submitted. Polling for results.');10 client.waitForTestToComplete(data.data.testId, function (err, data) {11 if (err) return console.error(err);12 console.log('Got results for ' + data.data.summary);13 var testResults = data.data;14 var testId = testResults.testId;15 var testUrl = testResults.summary;16 var testResultsUrl = testResults.userUrl;17 var testJsonUrl = testResults.jsonUrl;18 var testVideoUrl = testResults.videoUrl;19 var testScreenshotsUrl = testResults.screenshots;20 var testFirstView = testResults.data.average.firstView;21 var testFirstViewY = testFirstView.yPos;22 var testFirstViewYMax = testFirstView.yPosMax;23 var testFirstViewYMin = testFirstView.yPosMin;24 var testFirstViewYAvg = testFirstView.yPosAvg;25 var testFirstViewYStdDev = testFirstView.yPosStdDev;26 var testFirstViewYMedian = testFirstView.yPosMedian;27 var testFirstViewY95 = testFirstView.yPos95;28 var testFirstViewY99 = testFirstView.yPos99;29 var testFirstViewYStartRender = testFirstView.yPosStartRender;30 var testFirstViewYDocTime = testFirstView.yPosDocTime;31 var testFirstViewYFullyLoaded = testFirstView.yPosFullyLoaded;32 var testFirstViewYDomElements = testFirstView.yPosDomElements;33 var testFirstViewYDomElementsMax = testFirstView.yPosDomElementsMax;

Full Screen

Using AI Code Generation

copy

Full Screen

1var ypos = wpt.ypos();2alert("Y position is " + ypos);3var xpos = wpt.xpos();4alert("X position is " + xpos);5wpt.scroll(0, 100);6wpt.scrollX(100);7wpt.scrollY(100);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = wpt('www.webpagetest.org', options);5 if (err) return console.log(err);6 console.log(data);7 test.getTestStatus(data.data.testId, function(err, data) {8 console.log(data);9 });10});11### wpt(options)12var wpt = require('webpagetest');13var options = {14};15var test = wpt('www.webpagetest.org', options);16### test.runTest(url, options, callback)17 if (err) return console.log(err);18 console.log(data);19});20### test.getTestStatus(testId, callback)21test.getTestStatus('130624_9C_3P', function(err, data) {22 if (err) return console.log(err);23 console.log(data);24});25### test.getTestResults(testId, callback)26test.getTestResults('130624_9C_3P', function(err, data) {27 if (err) return console.log(err);28 console.log(data);29});30### test.getLocations(callback)31test.getLocations(function(err, data) {32 if (err) return console.log(err);33 console.log(data);34});35### test.getTesters(callback)36test.getTesters(function(err, data) {37 if (err) return console.log(err);38 console.log(data);39});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var fs = require('fs');3var options = {4};5var wpt = new WebPageTest('www.webpagetest.org', options.key);6wpt.runTest(testUrl, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test Results: %j', data);9 console.log('Test URL: %s', data.data.userUrl);10 console.log('Test ID: %s', data.data.testId);11 console.log('Test Status: %s', data.data.statusText);12 console.log('Test Running: %s', data.data.completeTime);13 console.log('Test Result: %s', data.data.summary);14 console.log('Test Result: %s', data.data.median.firstView);15 console.log('Test Result: %s', data.data.median.firstView.SpeedIndex);16 console.log('Test Result: %s', data.data.median.firstView.TTFB);17 console.log('Test Result: %s', data.data.median.firstView.render);18 console.log('Test Result: %s', data.data.median.firstView.fullyLoaded);19 console.log('Test Result: %s', data.data.median.firstView.docTime);20 console.log('Test Result: %s', data.data.median.firstView.loadTime);21 console.log('Test Result: %s', data.data.median.firstView.lastVisualChange);22 console.log('Test Result: %s', data.data.median.firstView.visualComplete85);23 console.log('Test Result: %s', data.data.median.firstView.visualComplete95);24 console.log('Test Result: %s', data.data.median.firstView.visualComplete99);25 console.log('Test Result: %s', data.data.median.firstView.lastVisualChange);26 console.log('Test Result: %s', data.data.median.firstView.SpeedIndex);27 console.log('Test Result:

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var webPageTest = new wpt('www.webpagetest.org', options);5 if (err) return console.error(err);6 console.log(data);7 console.log(data.data.median.firstView.SpeedIndex);8 console.log(data.data.median.firstView.y);9 console.log(data.data.median.firstView.ypos);10 console.log(data.data.median.firstView.yPos);11});12var lastElement = data.data.median.firstView.docTime[Object.keys(data.data.median.firstView.docTime)[Object.keys(data.data.median.firstView.docTime).length - 1]];13console.log(lastElement.y);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful