Difference between revisions of "Team:Cornell/sandbox"
(Created page with " <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-wi...") |
|||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html lang="en"> | <html lang="en"> | ||
+ | <!-- Make sure the <html> tag is set to the .full CSS class. Change the background image in the full.css file. --> | ||
<head> | <head> | ||
− | + | <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
− | + | <script type="text/javascript"> | |
− | + | (function($) { | |
− | + | $.fn.turniquet = function(options) { | |
− | + | // This is the easiest way to have default options. | |
− | + | var settings = $.extend({ | |
− | + | // These are the defaults. | |
− | + | zindex : 10000, | |
− | + | direction: 'up', | |
− | + | duration: 200, | |
− | + | easing: 'swing', | |
− | + | animateOnCLick: true, | |
− | + | triggerUp: null, | |
− | + | triggerDown: null, | |
− | + | complete: null, | |
− | + | before: null, | |
− | + | after: null | |
− | + | }, options); | |
− | + | ||
− | + | var windowWidth = this.parent().width(), | |
− | + | windowHeight = this.parent().height(), | |
− | + | zIndexI = settings.zindex, | |
+ | children = this.children(), | ||
+ | nbChild = children.length, | ||
+ | childWidth = $(children[0]).width(), | ||
+ | childHeight = $(children[0]).height(), | ||
+ | positions = [], | ||
+ | animationCounter = 0; | ||
+ | |||
+ | var animate = function(direction){ | ||
+ | if(typeof direction != 'string'){ | ||
+ | direction = settings.direction; | ||
+ | } | ||
+ | |||
+ | if(animationCounter == 0){ | ||
+ | var $e = $(this); | ||
+ | |||
+ | // for each child of main collection | ||
+ | children.each(function(index, element){ | ||
+ | var $c = $(element), | ||
+ | dataIndex = parseInt($c.attr('data-index')) | ||
+ | newIndex = 0, | ||
+ | down = null, | ||
+ | animTop = '', | ||
+ | animLeft = ''; | ||
+ | |||
+ | if(direction == 'up'){// up | ||
+ | newIndex = nbChild-1; | ||
+ | down = true; | ||
+ | if(dataIndex > 0){ | ||
+ | newIndex = dataIndex-1; | ||
+ | down = false; | ||
+ | } | ||
+ | }else{ // down | ||
+ | newIndex = 0; | ||
+ | down = false | ||
+ | if(dataIndex < (nbChild-1)){ | ||
+ | newIndex = dataIndex+1; | ||
+ | down = true; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Change data index | ||
+ | $c.attr('data-index', newIndex); | ||
+ | |||
+ | // Trigger before method | ||
+ | if(typeof settings.before == 'function'){ | ||
+ | settings.before(index, element); | ||
+ | } | ||
+ | |||
+ | if(!down){ | ||
+ | animTop = '-='+($c.position().top - positions[newIndex].top); | ||
+ | animLeft = '-='+($c.position().left - positions[newIndex].left); | ||
+ | }else{ | ||
+ | if(direction == 'up'){ | ||
+ | animTop = '+='+($c.position().top + positions[newIndex].top); | ||
+ | animLeft = '+='+($c.position().left + positions[newIndex].left); | ||
+ | }else{ | ||
+ | animTop = '+='+(positions[newIndex].top - $c.position().top); | ||
+ | animLeft = '+='+(positions[newIndex].left - $c.position().left); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | animationCounter++; | ||
+ | |||
+ | // change z-index | ||
+ | if(direction == 'up'){ | ||
+ | $c.css('z-index', positions[newIndex].zindex); | ||
+ | }else{// delay z-index | ||
+ | var ozIndex = { | ||
+ | zindex : positions[newIndex].zindex | ||
+ | }; | ||
+ | setTimeout(function(){ | ||
+ | $c.css('z-index', ozIndex.zindex); | ||
+ | }, settings.duration); | ||
+ | } | ||
+ | |||
+ | // Animate slides | ||
+ | $c.animate({ | ||
+ | left: animLeft, | ||
+ | top: animTop | ||
+ | }, settings.duration, settings.easing, function(){ | ||
+ | if(animationCounter > 0){ | ||
+ | animationCounter --; | ||
+ | } | ||
+ | }); | ||
+ | // Trigger before method | ||
+ | if(typeof settings.before == 'function'){ | ||
+ | setTimeout(function(){ | ||
+ | settings.after(index, element); | ||
+ | }, settings.duration); | ||
+ | } | ||
+ | |||
+ | }); | ||
+ | // Trigger complete method | ||
+ | if(typeof settings.complete == 'function'){ | ||
+ | setTimeout(settings.complete, settings.duration); | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | // Initilize First Position | ||
+ | children.each(function(index, element){ | ||
+ | var $e = $(element); | ||
+ | zIndexI--; | ||
+ | |||
+ | // Calculate position of each slide | ||
+ | var left = (((windowWidth-(childWidth))/(nbChild-1))*index); | ||
+ | var top = (((windowHeight-(childHeight))/(nbChild-1))*index); | ||
+ | |||
+ | positions[index] = { | ||
+ | 'top':top, | ||
+ | 'left':left, | ||
+ | 'zindex':zIndexI | ||
+ | }; | ||
+ | |||
+ | // Position slides | ||
+ | $e.css('top', top) | ||
+ | .css('left', left) | ||
+ | .css('z-index', zIndexI) | ||
+ | .attr('data-index', index); | ||
+ | }); | ||
+ | |||
+ | //Manage Click | ||
+ | if(settings.animateOnCLick){ | ||
+ | children.click(animate); | ||
+ | } | ||
+ | |||
+ | if(settings.triggerUp != null){ | ||
+ | var $triggerUp = $(settings.triggerUp); | ||
+ | if($triggerUp.length > 0){ | ||
+ | $triggerUp.click(function(){ | ||
+ | animate('up'); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(settings.triggerDown != null){ | ||
+ | var $triggerDown = $(settings.triggerDown); | ||
+ | if($triggerDown.length > 0){ | ||
+ | $triggerDown.click(function(){ | ||
+ | animate('down'); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return this; | ||
+ | }; | ||
+ | |||
+ | }(jQuery)); | ||
+ | |||
+ | $('.turniquet').turniquet(); | ||
+ | </script> | ||
+ | <style type="text/css"> | ||
+ | .jumbotron { | ||
+ | position: relative; | ||
+ | height: 600px; | ||
+ | } | ||
+ | .turniquet { | ||
+ | position: relative; | ||
+ | margin:0; | ||
+ | } | ||
+ | .turniquet li { | ||
+ | position:absolute; | ||
+ | display:block; | ||
+ | width:350px; | ||
+ | height:350px; | ||
+ | list-style: none; | ||
+ | max-height: 80px; | ||
+ | } | ||
+ | </style> | ||
</head> | </head> | ||
− | |||
<body> | <body> | ||
− | + | <div class="jumbotron"> | |
− | + | <ul class="turniquet"> | |
− | + | <li><img src="https://static.igem.org/mediawiki/2014/5/5b/BlackG_igem_logo.png" /></li> | |
− | < | + | <li><img src="https://static.igem.org/mediawiki/2014/5/5b/BlackG_igem_logo.png" /></li> |
− | < | + | <li><img src="https://static.igem.org/mediawiki/2014/5/5b/BlackG_igem_logo.png" /></li> |
− | + | </ul> | |
− | + | </div> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | < | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </ | + | |
− | + | ||
− | </ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</body> | </body> | ||
</html> | </html> |
Latest revision as of 23:53, 14 September 2015
<!DOCTYPE html>