Team:UCLA/Template/Javascript

From 2014.igem.org

(Difference between revisions)
 
(74 intermediate revisions not shown)
Line 1: Line 1:
<html>
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
 +
<!--SPIDER TOP BUTTON-->
 +
<script type="text/javascript">
 +
jQuery(document).ready(function($){
 +
    $('.spiderbutton, .backtotop').click(function(){
 +
          $('.spiderbutton').stop(true,true).animate({ top: '-=55%'}, 800, function(){$('.spiderbutton').stop(true,true).animate({ top: '+=55%'}, 3000)});
 +
          $('.spiderline').stop(true,true).animate({ top: '-=55%'}, 800, function(){$('.spiderline').stop(true,true).animate({ top: '+=55%'}, 3000)});
 +
          $("html, body").animate({ scrollTop: 0 }, 1000);
 +
    });
 +
});
 +
</script>
 +
 +
 +
<!--SPLASH PAGE-->
 +
<script type="text/javascript">
 +
    $(document).ready(function() {
 +
        $('#box1').hover(function(){
 +
            var smallTop = $('#box1').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
        $('#box2').hover(function(){
 +
            var smallTop = $('#box2').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
                $('#box3').hover(function(){
 +
            var smallTop = $('#box3').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
                $('#box4').hover(function(){
 +
            var smallTop = $('#box4').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
    });
 +
</script>
 +
 +
<!--MAIN PAGE BOXES-->
 +
<script type="text/javascript">
 +
    $(document).ready(function() {
 +
        $('#box5').hover(function(){
 +
            var smallTop = $('#box5').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
        $('#box6').hover(function(){
 +
            var smallTop = $('#box6').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
                $('#box7').hover(function(){
 +
            var smallTop = $('#box7').height() - $(".cover", this).height() -10 +"px";
 +
    $(".cover", this).stop().animate({top:smallTop},{queue:false,duration:160});
 +
}, function() {
 +
    $(".cover", this).stop().animate({top:'340px'},{queue:false,duration:160});
 +
});
 +
    });
 +
</script>
 +
 +
 +
<!--SIDE NAVIGATION MENU BAR-->
 +
<script type="text/javascript">
 +
$(document).ready(function(){
 +
  $("#side_menu").mouseenter(function(){
 +
    $("#side_menu").stop(true,false).animate({
 +
      left:'0px',
 +
    });
 +
  }).mouseleave(function(){
 +
    $("#side_menu").stop(true,false).animate({
 +
      left:'-170px',
 +
    });
 +
  });
 +
});
 +
</script>
<!--TOP NAVIGATION MENU BAR-->
<!--TOP NAVIGATION MENU BAR-->
Line 7: Line 88:
$("#menu > li > ul").hide();
$("#menu > li > ul").hide();
$("#menu > li").mouseenter(function() {
$("#menu > li").mouseenter(function() {
-
$(this).children("li > ul").slideDown(500);
+
$(this).children("li > ul").stop(true,true).slideDown(350);
});
});
         $("#menu > li").mouseleave(function() {
         $("#menu > li").mouseleave(function() {
-
$(this).children("li > ul").slideUp(500);
+
$(this).children("li > ul").stop(true,true).slideUp(350);
});
});
});
});
Line 51: Line 132:
};
};
})(jQuery);
})(jQuery);
-
 
$(document).ready(function(){
$(document).ready(function(){
Line 70: Line 150:
</script>
</script>
-
<!--SLIDER-->
 
-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 
-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
 
-
<script type="text/javascript">
 
-
function Slider(){
 
-
$(".slider #1").show("fade",500);
 
-
$(".slider #1").delay(3000).hide("slide",{direction:'left'},500);
 
-
 
-
var sc = $(".slider img").size();
 
-
var count = 2;
 
-
 
-
setInterval(function(){
 
-
$(".slider #"+count).show("slide",{direction:'right'},500);
 
-
$(".slider #"+count).delay(3000).hide("slide",{direction:'left'},500);
 
-
if(count == sc){
 
-
count = 1;
 
-
}else{
 
-
count += 1;
 
-
}
 
-
},4000);
 
-
}
 
-
</script>
 
-
<!-- SAM'S CAROUSEL EDIT SORRY AGAIN -->
 
-
<script type="text/javascript">
 
-
$(".scroll").click(function(event){
 
-
event.preventDefault();
 
-
//calculate destination place
 
-
var dest=0;
 
-
if($(this.hash).offset().top > $(document).height()-$(window).height()){
 
-
dest=$(document).height()-$(window).height();
 
-
}else{
 
-
dest=$(this.hash).offset().top;
 
-
}
 
-
//go to destination
 
-
$('html,body').animate({scrollTop:dest}, 700,'swing');
 
-
});
 
-
</script>
 
-
<!--BACK TO TOP BUTTON-->
+
<!--SLIDER-->
<script type="text/javascript">
<script type="text/javascript">
-
$(function(){
+
  $(document).ready(function() {
-
$(document).on( 'scroll', function(){
+
    $('.slider_left').mouseenter(function(){
-
if ($(window).scrollTop() > 100) {
+
          $('.slider_left').animate({ opacity: '0.8'},1);
-
$('.scroll-top-wrapper').addClass('show');
+
    });
-
} else {
+
    $('.slider_right').mouseenter(function(){
-
$('.scroll-top-wrapper').removeClass('show');
+
          $('.slider_right').animate({ opacity: '0.8'},1);
-
}
+
    });
-
});
+
    $('.slider_left').mouseleave(function(){
-
$('.scroll-top-wrapper').on('click', scrollToTop);
+
          $('.slider_left').animate({ opacity: '0.5'},1);
-
});
+
    });
-
+
    $('.slider_right').mouseleave(function(){
-
function scrollToTop() {
+
          $('.slider_right').animate({ opacity: '0.5'},1);
-
verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0;
+
    });
-
element = $('body');
+
-
offset = element.offset();
+
-
offsetTop = offset.top;
+
-
$('html, body').animate({scrollTop: offsetTop},700, 'swing');
+
-
};
+
-
$(".scroll").click(function(event){
+
    var total = $('.slider_imgs > td').length;
-
event.preventDefault();
+
    var count = 0;
-
//calculate destination place
+
    $('.slider_left').click(function(){
-
var dest=0;
+
        if(count > 0){
-
if($(this.hash).offset().top > $(document).height()-$(window).height()){
+
            $('.slider_imgs').stop(true,true).animate({ left: '+=1150px'}, 250);
-
dest=$(document).height()-$(window).height();
+
            count -= 1;
-
}else{
+
        } else{
-
dest=$(this.hash).offset().top;
+
            $('.slider_imgs').stop(true,true).animate({ left: '+=20px'}, 100, function(){$('.slider_imgs').stop(true,true).animate({ left: '-=20px'}, 500)});
-
}
+
        }
-
//go to destination
+
    });
-
$('html,body').animate({scrollTop:dest}, 700,'swing');
+
    $('.slider_right').click(function(){
-
});
+
        if(count < 3){
 +
            $('.slider_imgs').stop(true,true).animate({ left: '-=1150px'}, 250);
 +
            count += 1;
 +
        } else{
 +
            $('.slider_imgs').stop(true,true).animate({ left: '+=3450px'}, 250);
 +
            count = 0;
 +
        }
 +
    });
 +
  });
 +
</script>
-
<!-- TEARABLE CLOTH -->
 
-
var physics_accuracy = 3,
 
-
    mouse_influence = 20,
 
-
    mouse_cut = 5,
 
-
    gravity = 1200,
 
-
    cloth_height = 730,
 
-
    cloth_width = 750,
 
-
    start_y = 620,
 
-
    spacing = 7,
 
-
    tear_distance = 60;
 
 +
<!--HP SLIDER-->
 +
<script type="text/javascript">
 +
  $(document).ready(function() {
 +
    $('.hpslider_left').mouseenter(function(){
 +
          $('.hpslider_left').animate({ opacity: '0.8'},1);
 +
    });
 +
    $('.hpslider_right').mouseenter(function(){
 +
          $('.hpslider_right').animate({ opacity: '0.8'},1);
 +
    });
 +
    $('.hpslider_left').mouseleave(function(){
 +
          $('.hpslider_left').animate({ opacity: '0.5'},1);
 +
    });
 +
    $('.hpslider_right').mouseleave(function(){
 +
          $('.hpslider_right').animate({ opacity: '0.5'},1);
 +
    });
-
window.requestAnimFrame =
 
-
    window.requestAnimationFrame ||
 
-
    window.webkitRequestAnimationFrame ||
 
-
    window.mozRequestAnimationFrame ||
 
-
    window.oRequestAnimationFrame ||
 
-
    window.msRequestAnimationFrame ||
 
-
    function (callback) {
 
-
        window.setTimeout(callback, 1000 / 60);
 
-
};
 
-
var canvas,
+
    var total = $('.hpslider_imgs > td').length;
-
    ctx,
+
    var count = 0;
-
    cloth,
+
    $('.hpslider_left').click(function(){
-
    boundsx,
+
        if(count > 0){
-
    boundsy,
+
             $('.hpslider_imgs').stop(true,true).animate({ left: '+=1150px'}, 250);
-
    mouse = {
+
            count -= 1;
-
        down: false,
+
         } else{
-
        button: 1,
+
             $('.hpslider_imgs').stop(true,true).animate({ left: '-=16100px'}, 250);
-
        x: 0,
+
            count = 14;
-
        y: 0,
+
//            $('.hpslider_imgs').stop(true,true).animate({ left: '+=20px'}, 100, function(){$('.hpslider_imgs').stop(true,true).animate({ left: '-=20px'}, 500)});
-
        px: 0,
+
         }
-
        py: 0
+
    });
-
    };
+
    $('.hpslider_right').click(function(){
-
 
+
         if(count < 14){
-
var Point = function (x, y) {
+
            $('.hpslider_imgs').stop(true,true).animate({ left: '-=1150px'}, 250);
-
 
+
            count += 1;
-
    this.x = x;
+
        } else{
-
    this.y = y;
+
            $('.hpslider_imgs').stop(true,true).animate({ left: '+=16100px'}, 250);
-
    this.px = x;
+
             count = 0;
-
    this.py = y;
+
-
    this.vx = 0;
+
-
    this.vy = 0;
+
-
    this.pin_x = null;
+
-
    this.pin_y = null;
+
-
 
+
-
    this.constraints = [];
+
-
};
+
-
 
+
-
Point.prototype.update = function (delta) {
+
-
 
+
-
    if (mouse.down) {
+
-
 
+
-
        var diff_x = this.x - mouse.x,
+
-
             diff_y = this.y - mouse.y,
+
-
            dist = Math.sqrt(diff_x * diff_x + diff_y * diff_y);
+
-
 
+
-
         if (mouse.button == 1) {
+
-
 
+
-
             if (dist < mouse_influence) {
+
-
                this.px = this.x - (mouse.x - mouse.px) * 1.8;
+
-
                this.py = this.y - (mouse.y - mouse.py) * 1.8;
+
-
            }
+
-
 
+
-
        } else if (dist < mouse_cut) this.constraints = [];
+
-
    }
+
-
 
+
-
    this.add_force(0, gravity);
+
-
 
+
-
    delta *= delta;
+
-
    nx = this.x + ((this.x - this.px) * .99) + ((this.vx / 2) * delta);
+
-
    ny = this.y + ((this.y - this.py) * .99) + ((this.vy / 2) * delta);
+
-
 
+
-
    this.px = this.x;
+
-
    this.py = this.y;
+
-
 
+
-
    this.x = nx;
+
-
    this.y = ny;
+
-
 
+
-
    this.vy = this.vx = 0
+
-
};
+
-
 
+
-
Point.prototype.draw = function () {
+
-
 
+
-
    if (this.constraints.length <= 0) return;
+
-
 
+
-
    var i = this.constraints.length;
+
-
    while (i--) this.constraints[i].draw();
+
-
};
+
-
 
+
-
Point.prototype.resolve_constraints = function () {
+
-
 
+
-
    if (this.pin_x != null && this.pin_y != null) {
+
-
 
+
-
        this.x = this.pin_x;
+
-
        this.y = this.pin_y;
+
-
        return;
+
-
    }
+
-
 
+
-
    var i = this.constraints.length;
+
-
    while (i--) this.constraints[i].resolve();
+
-
 
+
-
    if (this.x > boundsx) {
+
-
 
+
-
         this.x = 2 * boundsx - this.x;
+
-
       
+
-
    } else if (this.x < 1) {
+
-
 
+
-
        this.x = 2 - this.x;
+
-
    }
+
-
 
+
-
    if (this.y > boundsy) {
+
-
 
+
-
        this.y = 2 * boundsy - this.y;
+
-
       
+
-
    } else if (this.y < 1) {
+
-
 
+
-
        this.y = 2 - this.y;
+
-
    }
+
-
};
+
-
 
+
-
Point.prototype.attach = function (point) {
+
-
 
+
-
    this.constraints.push(
+
-
        new Constraint(this, point)
+
-
    );
+
-
};
+
-
 
+
-
Point.prototype.remove_constraint = function (lnk) {
+
-
 
+
-
    var i = this.constraints.length;
+
-
    while (i--)
+
-
         if (this.constraints[i] == lnk) this.constraints.splice(i, 1);
+
-
};
+
-
 
+
-
Point.prototype.add_force = function (x, y) {
+
-
 
+
-
    this.vx += x;
+
-
    this.vy += y;
+
-
};
+
-
 
+
-
Point.prototype.pin = function (pinx, piny) {
+
-
    this.pin_x = pinx;
+
-
    this.pin_y = piny;
+
-
};
+
-
 
+
-
var Constraint = function (p1, p2) {
+
-
 
+
-
    this.p1 = p1;
+
-
    this.p2 = p2;
+
-
    this.length = spacing;
+
-
};
+
-
 
+
-
Constraint.prototype.resolve = function () {
+
-
 
+
-
    var diff_x = this.p1.x - this.p2.x,
+
-
        diff_y = this.p1.y - this.p2.y,
+
-
        dist = Math.sqrt(diff_x * diff_x + diff_y * diff_y),
+
-
        diff = (this.length - dist) / dist;
+
-
 
+
-
    if (dist > tear_distance) this.p1.remove_constraint(this);
+
-
 
+
-
    var px = diff_x * diff * 0.5;
+
-
    var py = diff_y * diff * 0.5;
+
-
 
+
-
    this.p1.x += px;
+
-
    this.p1.y += py;
+
-
    this.p2.x -= px;
+
-
    this.p2.y -= py;
+
-
};
+
-
 
+
-
Constraint.prototype.draw = function () {
+
-
 
+
-
    ctx.moveTo(this.p1.x, this.p1.y);
+
-
    ctx.lineTo(this.p2.x, this.p2.y);
+
-
};
+
-
 
+
-
var Cloth = function () {
+
-
 
+
-
    this.points = [];
+
-
 
+
-
    var start_x = canvas.width / 2 - cloth_width * spacing / 2;
+
-
 
+
-
    for (var y = 0; y <= cloth_height; y++) {
+
-
 
+
-
        for (var x = 0; x <= cloth_width; x++) {
+
-
 
+
-
            var p = new Point(start_x + x * spacing, start_y + y * spacing);
+
-
 
+
-
             x != 0 && p.attach(this.points[this.points.length - 1]);
+
-
            y == 0 && p.pin(p.x, p.y);
+
-
            y != 0 && p.attach(this.points[x + (y - 1) * (cloth_width + 1)])
+
-
 
+
-
            this.points.push(p);
+
         }
         }
-
    }
+
    });
-
};
+
  });
 +
</script>
-
Cloth.prototype.update = function () {
 
-
    var i = physics_accuracy;
 
-
    while (i--) {
 
-
        var p = this.points.length;
 
-
        while (p--) this.points[p].resolve_constraints();
 
-
    }
 
-
    i = this.points.length;
+
<!--PAGE HEADERS-->
-
    while (i--) this.points[i].update(.016);
+
<script type="text/javascript">
-
};
+
$(document).ready(function() {
 +
    $('.page_header_box').mouseenter(function(){
 +
          $(this).animate({ opacity: '0.9'},1);
 +
    });
 +
    $('.page_header_box').mouseleave(function(){
 +
          $(this).animate({ opacity: '0.5'},1);
 +
    });
 +
});
 +
</script>
-
Cloth.prototype.draw = function () {
 
-
 
-
    ctx.beginPath();
 
-
 
-
    var i = cloth.points.length;
 
-
    while (i--) cloth.points[i].draw();
 
-
 
-
    ctx.stroke();
 
-
};
 
-
 
-
function update() {
 
-
 
-
    ctx.clearRect(0, 0, canvas.width, canvas.height);
 
-
 
-
    cloth.update();
 
-
    cloth.draw();
 
-
 
-
    requestAnimFrame(update);
 
-
}
 
-
 
-
function start() {
 
-
 
-
    canvas.onmousedown = function (e) {
 
-
        mouse.button = e.which;
 
-
        mouse.px = mouse.x;
 
-
        mouse.py = mouse.y;
 
-
        var rect = canvas.getBoundingClientRect();
 
-
        mouse.x = e.clientX - rect.left,
 
-
        mouse.y = e.clientY - rect.top,
 
-
        mouse.down = true;
 
-
        e.preventDefault();
 
-
    };
 
-
 
-
    canvas.onmouseup = function (e) {
 
-
        mouse.down = false;
 
-
        e.preventDefault();
 
-
    };
 
-
 
-
    canvas.onmousemove = function (e) {
 
-
        mouse.px = mouse.x;
 
-
        mouse.py = mouse.y;
 
-
        var rect = canvas.getBoundingClientRect();
 
-
        mouse.x = e.clientX - rect.left,
 
-
        mouse.y = e.clientY - rect.top,
 
-
        e.preventDefault();
 
-
    };
 
-
 
-
    canvas.oncontextmenu = function (e) {
 
-
        e.preventDefault();
 
-
    };
 
-
 
-
    boundsx = canvas.width - 1;
 
-
    boundsy = canvas.height - 1;
 
-
 
-
    ctx.strokeStyle = '#888';
 
-
    cloth = new Cloth();
 
-
    update();
 
-
}
 
-
 
-
window.onload = function () {
 
-
 
-
    canvas = document.getElementById('c');
 
-
    ctx = canvas.getContext('2d');
 
-
 
-
    canvas.width = 560;
 
-
    canvas.height = 350;
 
-
 
-
    start();
 
-
};
 
-
 
-
 
-
</script>
 
</html>
</html>

Latest revision as of 02:45, 18 October 2014