global.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. jQuery(document).ready(function($) {
  2. // Toggle mobile-menu
  3. $(".nav-toggle").on("click", function(){
  4. $(this).toggleClass("active");
  5. $(".mobile-menu").slideToggle();
  6. if ($(".search-toggle").hasClass("active")) {
  7. $(".search-toggle").removeClass("active");
  8. $(".blog-search").slideToggle();
  9. }
  10. });
  11. // Toggle search form
  12. $(".search-toggle").on("click", function(){
  13. $(this).toggleClass("active");
  14. $(".blog-search").slideToggle();
  15. if ($(".nav-toggle").hasClass("active")) {
  16. $(".nav-toggle").removeClass("active");
  17. $(".mobile-menu").slideToggle();
  18. }
  19. });
  20. // Show mobile-menu > 700
  21. $(window).resize(function() {
  22. if ($(window).width() > 800) {
  23. $(".toggle").removeClass("active");
  24. $(".mobile-menu").hide();
  25. $(".blog-search").hide();
  26. }
  27. });
  28. // Cool header image scroll
  29. $(window).scroll(function(e){
  30. if ($(window).width() > 800) {
  31. $('.header').css({
  32. 'bottom' : -($(this).scrollTop()/3)+"px",
  33. });
  34. var thisdist = $(this).scrollTop();
  35. var headerheight = $(".header").outerHeight();
  36. $('.blog-info').css({
  37. 'opacity' : (1 - thisdist/headerheight)
  38. });
  39. } else {
  40. $('.header').css({'bottom' : 'auto'});
  41. $('.blog-info').css({'opacity' : "1" });
  42. }
  43. });
  44. // resize videos after container
  45. var vidSelector = ".post iframe, .post object, .post video, .widget-content iframe, .widget-content object, .widget-content iframe";
  46. var resizeVideo = function(sSel) {
  47. $( sSel ).each(function() {
  48. var $video = $(this),
  49. $container = $video.parent(),
  50. iTargetWidth = $container.width();
  51. if ( !$video.attr("data-origwidth") ) {
  52. $video.attr("data-origwidth", $video.attr("width"));
  53. $video.attr("data-origheight", $video.attr("height"));
  54. }
  55. var ratio = iTargetWidth / $video.attr("data-origwidth");
  56. $video.css("width", iTargetWidth + "px");
  57. $video.css("height", ( $video.attr("data-origheight") * ratio ) + "px");
  58. });
  59. };
  60. resizeVideo(vidSelector);
  61. $(window).resize(function() {
  62. resizeVideo(vidSelector);
  63. });
  64. // Smooth scroll to header
  65. $('.tothetop').click(function(){
  66. $('html,body').animate({scrollTop: 0}, 500);
  67. $(this).unbind("mouseenter mouseleave");
  68. return false;
  69. });
  70. });