Difference between revisions of "Template:Pitt"
m |
|||
Line 12: | Line 12: | ||
(function($) { | (function($) { | ||
− | + | var defaults = { | |
− | + | topSpacing: 0, | |
− | + | bottomSpacing: 0, | |
− | + | className: 'is-sticky', | |
− | + | wrapperClassName: 'sticky-wrapper', | |
− | + | center: false, | |
− | + | getWidthFrom: '' | |
− | + | }, | |
− | + | $window = $(window), | |
− | + | $document = $(document), | |
− | + | sticked = [], | |
− | + | windowHeight = $window.height(), | |
− | + | scroller = function() { | |
− | + | var scrollTop = $window.scrollTop(), | |
− | + | documentHeight = $document.height(), | |
− | + | dwh = documentHeight - windowHeight, | |
− | + | extra = (scrollTop > dwh) ? dwh - scrollTop : 0; | |
− | + | for (var i = 0; i < sticked.length; i++) { | |
− | + | var s = sticked[i], | |
− | + | elementTop = s.stickyWrapper.offset().top, | |
− | + | etse = elementTop - s.topSpacing - extra; | |
− | + | if (scrollTop <= etse) { | |
− | + | if (s.currentTop !== null) { | |
− | + | s.stickyElement.css('position', '').css('top', ''); | |
− | + | s.stickyElement.parent().removeClass(s.className); | |
− | + | $("#menuContainer td").stop(true, false).animate({backgroundColor: '#000000'}, 250); | |
− | + | $("#menuContainer table").stop(true, false).animate({backgroundColor: '#000000'}, 250); | |
− | + | $("#menuContainer li").css({backgroundColor: '#000000'}); | |
− | + | $("#top_menu_14").removeClass("opaque"); | |
− | + | $("#top_menu_14").not(".mouseOver").stop().fadeTo(250, 0.2); | |
− | + | s.currentTop = null; | |
− | + | } | |
− | + | } else { | |
− | + | var newTop = documentHeight - s.stickyElement.outerHeight() - s.topSpacing - s.bottomSpacing - scrollTop - extra; | |
− | + | if (newTop < 0) { | |
− | + | newTop = newTop + s.topSpacing; | |
− | + | } else { | |
− | + | newTop = s.topSpacing; | |
− | + | } | |
− | + | if (s.currentTop != newTop) { | |
− | + | s.stickyElement.css('position', 'fixed').css('top', newTop); | |
− | + | if (typeof s.getWidthFrom !== 'undefined') { | |
− | + | s.stickyElement.css('width', $(s.getWidthFrom).width()); | |
− | + | } | |
− | + | $("#menuContainer td").stop(true, false).animate({backgroundColor: '#00043d'}, 250); | |
− | + | $("#menuContainer table").stop(true, false).animate({backgroundColor: '#00043d'}, 250); | |
− | + | $("#menuContainer li").css({backgroundColor: '#00043d'}); | |
+ | s.stickyElement.parent().addClass(s.className); | ||
+ | $("#top_menu_14").addClass("opaque"); | ||
+ | $("#top_menu_14").stop().fadeTo(250, 1); | ||
+ | s.currentTop = newTop; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | }, | ||
+ | resizer = function() { | ||
+ | windowHeight = $window.height(); | ||
+ | $("#menuContainer td:has(ul)").children("ul").each(function(){ | ||
+ | var padding = parseInt($(this).parent().css("padding-left")) + parseInt($(this).parent().css("padding-right")); | ||
+ | var newWidth = parseInt($(this).parent().css("width")) + padding; | ||
+ | $(this).css("width", newWidth + 'px'); | ||
+ | }); | ||
+ | }, | ||
+ | methods = { | ||
+ | init: function(options) { | ||
+ | var o = $.extend(defaults, options); | ||
+ | return this.each(function() { | ||
+ | var stickyElement = $(this); | ||
− | + | stickyId = stickyElement.attr('id'); | |
− | + | wrapper = $('<div></div>').attr('id', stickyId + '-sticky-wrapper').addClass(o.wrapperClassName); | |
− | + | stickyElement.wrapAll(wrapper); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | if (o.center) { | |
− | + | stickyElement.parent().css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"}); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | if (stickyElement.css("float") == "right") { | |
− | + | stickyElement.css({"float":"none"}).parent().css({"float":"right"}); | |
− | + | } | |
− | + | var stickyWrapper = stickyElement.parent(); | |
− | + | stickyWrapper.css('height', stickyElement.outerHeight()); | |
− | + | sticked.push({ | |
+ | topSpacing: o.topSpacing, | ||
+ | bottomSpacing: o.bottomSpacing, | ||
+ | stickyElement: stickyElement, | ||
+ | currentTop: null, | ||
+ | stickyWrapper: stickyWrapper, | ||
+ | className: o.className, | ||
+ | getWidthFrom: o.getWidthFrom | ||
+ | }); | ||
+ | }); | ||
+ | }, | ||
+ | update: scroller | ||
+ | }; | ||
− | + | if (window.addEventListener) { | |
− | + | window.addEventListener('scroll', scroller, false); | |
− | + | window.addEventListener('resize', resizer, false); | |
− | + | } else if (window.attachEvent) { | |
− | + | window.attachEvent('onscroll', scroller); | |
− | + | window.attachEvent('onresize', resizer); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | $.fn.sticky = function(method) { | |
− | + | return methods.init.apply( this, arguments ); | |
− | + | }; | |
− | + | $(function() { | |
− | + | setTimeout(scroller, 0); | |
− | + | }); | |
})(jQuery); | })(jQuery); | ||
Line 252: | Line 242: | ||
</div>\ | </div>\ | ||
"); | "); | ||
− | |||
− | |||
− | |||
var c = document.getElementById("bannerCanvas"); | var c = document.getElementById("bannerCanvas"); | ||
− | c.height = $( | + | c.height = $(document).height() / 10; |
− | c.width = $( | + | c.width = $(document).width() / 10; |
− | var ctx = c.getContext( | + | var ctx = c.getContext('2d'); |
− | + | ctx.fillRect(0, 0, c.width, c.height); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | $("#bannerContainer").mousemove(function(event){ | |
− | ctx. | + | var c = document.getElementById("bannerCanvas"); |
+ | var ctx = c.getContext('2d'); | ||
+ | var iD= ctx.getImageData(0, 0, c.width, c.height); | ||
+ | var data = iD.data; | ||
+ | var x, y, color; | ||
− | + | for(y = 0; y < c.height; y++) { | |
− | ctx. | + | for(x = 0; x < c.width; x++) { |
+ | color = 50 / c.width * Math.max(0, 2 * c.width - (10 * x - event.pageX) * (10 * x - event.pageX) - (10 * y - event.pageY) * (10 * y - event.pageY)) - 10; | ||
+ | data[((c.width * y) + x) * 4] += color; | ||
+ | data[((c.width * y) + x) * 4 + 1] += color; | ||
+ | data[((c.width * y) + x) * 4 + 2] += color; | ||
+ | } | ||
+ | } | ||
+ | ctx.putImageData(iD, 0, 0); | ||
}); | }); | ||
Line 282: | Line 275: | ||
* { | * { | ||
− | margin: 0; | + | margin: 0; |
− | padding: 0; | + | padding: 0; |
} | } | ||
Line 370: | Line 363: | ||
#banner { | #banner { | ||
− | + | aaaaabackground: url("https://static.igem.org/mediawiki/2015/7/75/Pittbanner.png"); | |
background-size: 100%; | background-size: 100%; | ||
background-repeat: no-repeat; | background-repeat: no-repeat; | ||
Line 420: | Line 413: | ||
position: relative; | position: relative; | ||
text-align: center; | text-align: center; | ||
− | background-color: #000000; | + | background-color: #000000; |
color: #ffffff; | color: #ffffff; | ||
margin: 0px; | margin: 0px; | ||
Line 427: | Line 420: | ||
#menuContainer table { | #menuContainer table { | ||
− | background-color: #000000; | + | background-color: #000000; |
− | width: 100%; | + | width: 100%; |
} | } | ||
Line 441: | Line 434: | ||
#bannerCanvas { | #bannerCanvas { | ||
− | + | position: absolute; | |
− | + | width: 100%; | |
− | z-index:-1; | + | z-index:-1; |
− | height: 100%; | + | height: 100%; |
− | left: 0; | + | left: 0; |
− | top: 0; | + | top: 0; |
} | } | ||
Revision as of 23:54, 4 June 2015