Skip to content

Commit e5eaba8

Browse files
Removed dependency on javascript code to generate background images for headers on all pages (it generated too much network traffic and was needlesly complicated) - used a simple <picture> element with an absolute positioning for the page title and overlay in pseudo after element. All is now easily configurable from the css.
Applied above to all existing pages. Created necessary global styles for the above in style.scss. Moved .page__title-container class to global styles at the top of styles.scss. Removed unused javascript code from site.js. Put that code into snippets.js - may be usefull one day.
1 parent 0ff2716 commit e5eaba8

File tree

11 files changed

+102
-90
lines changed

11 files changed

+102
-90
lines changed

_pages/01_about.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<section class="about">
88
<!--REPLACE THIS IMAGE WITH A NEW ONE - MIX PREVIOUS MEETUPS AND MAKE A COLLAGE -->
9-
<div class="about__background-img" data-image-type="responsive">
9+
<div class="about__background-img-container">
1010
<picture>
1111
<source srcset="../static/images/events_page/events_page_top_480x150px.jpg 480w,
1212
../static/images/events_page/events_page_top_960x300px.jpg 960w,
@@ -17,10 +17,9 @@
1717
../static/images/events_page/events_page_top_1650x1100px.jpg 1650w"
1818
media="(orientation: portrait)"
1919
sizes="100vw">
20-
<img class="responsive"
20+
<img class=""
2121
src="../static/images/events_page/events_page_top_960x300px.jpg"
22-
alt="Events"
23-
data-overlay="linear-gradient(180deg, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0.65) 100%)">
22+
alt="Events">
2423
</picture>
2524
<div class="about__page-title-container row container-fluid">
2625
<div class="col-sm-12">

_pages/03_events.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
permalink: /events/
55
---
66
<section class="events-page">
7-
<div class="events-page__background-img" data-image-type="responsive">
7+
<div class="events-page__background-img-container" data-image-type="responsive">
88
<picture>
99
<source srcset="../static/images/events_page/events_page_top_480x150px.jpg 480w,
1010
../static/images/events_page/events_page_top_960x300px.jpg 960w,
@@ -15,7 +15,7 @@
1515
../static/images/events_page/events_page_top_1650x1100px.jpg 1650w"
1616
media="(orientation: portrait)"
1717
sizes="100vw">
18-
<img class="responsive"
18+
<img class=""
1919
src="../static/images/events_page/events_page_top_960x300px.jpg"
2020
alt="Events"
2121
data-overlay="linear-gradient(180deg, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0.65) 100%)">

_pages/04_contact.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
permalink: /contact/
55
---
66
<section class="contact">
7-
<div class="contact__background-img" data-image-type="responsive">
7+
<div class="contact__background-img-container" data-image-type="responsive">
88
<picture>
99
<source srcset="../static/images/contact/contact_top_450x150px.jpg 450w,
1010
../static/images/contact/contact_top_960x300px.jpg 960w,
@@ -15,7 +15,7 @@
1515
../static/images/contact/contact_top_1650x1100px.jpg 1650w"
1616
media="(orientation: portrait)"
1717
sizes="100vw">
18-
<img class="responsive"
18+
<img class=""
1919
src="../static/images/contact/contact_top_960x300px.jpg"
2020
alt="Contact Us"
2121
data-overlay="linear-gradient(180deg, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.75) 100%)">

_sass/about.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
.about__background-img {
2-
@extend .contact__background-img;
1+
.about {
2+
margin-top: -66px;
3+
}
4+
5+
.about__background-img-container {
6+
@extend .page__background-img-container;
7+
&::after {
8+
background: rgba(0, 0, 0, 0.65);
9+
}
310
}
411

512
.about__page-title-container {
6-
@extend .page__title-container
13+
@extend .page__title-container;
714
}
815

916
.about__page-title {

_sass/contact.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
margin-top: -66px;
33
}
44

5-
.contact__background-img {
6-
height: 55vh;
5+
.contact__background-img-container {
6+
@extend .page__background-img-container;
7+
&::after {
8+
background: rgba(0, 0, 0, 0.65);
9+
}
710
}
811

912
.contact__page-title-container {

_sass/events.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
margin-top: -66px;
33
}
44

5-
.events-page__background-img {
6-
@extend .contact__background-img
5+
.events-page__background-img-container {
6+
@extend .page__background-img-container;
7+
&::after {
8+
background: rgba(0, 0, 0, 0.65);
9+
}
710
}
811

912
.events-page__title-container {

_sass/style.scss

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Global styles here.
2+
13
.body {
24
background-color: $main-background;
35
overflow-x: hidden;
@@ -36,6 +38,28 @@ a {
3638
padding-right: 15px;
3739
}
3840

41+
.page__background-img-container {
42+
position: relative;
43+
&::after {
44+
content: "";
45+
position: absolute;
46+
top: 0;
47+
right: 0;
48+
bottom: 0;
49+
left: 0;
50+
}
51+
}
52+
53+
.page__title-container {
54+
z-index: 2;
55+
position: absolute;
56+
top: 50%;
57+
-moz-transform: translateY(-50%);
58+
-webkit-transform: translateY(-50%);
59+
-ms-transform: translateY(-50%);
60+
transform: translateY(-50%);
61+
}
62+
3963
/* Classes to change order of collapsed columns on mobiles*/
4064
@media (max-width: 767px) {
4165
.first-on-mobile {
@@ -59,25 +83,14 @@ a {
5983
}
6084
}
6185

62-
/* Responsive background image handling*/
63-
[data-image-type="responsive"] {
64-
background-size: cover;
65-
background-position: center center;
66-
background-repeat: no-repeat;
67-
width: 100%;
68-
}
69-
70-
[data-image-type="responsive"] .responsive {
71-
display: none;
72-
}
73-
7486
/*Here I need to move the background image to slide under the navigation*/
7587
/*Any smarter solutions are welcome!*/
7688
.navigation__content {
77-
background-size: cover;
89+
@extend .page__background-img-container;
7890
margin-top: -66px;
79-
max-width: 100vw;
80-
height: 101vh;
91+
&::after {
92+
background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.8) 100%);
93+
}
8194
}
8295

8396
.navigation__brand {

_sass/typography.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@
3535
// Text styles below.
3636
// Page title.
3737

38-
.page__title-container {
39-
position: relative;
40-
top: 50%;
41-
-moz-transform: translateY(-50%);
42-
-webkit-transform: translateY(-50%);
43-
-ms-transform: translateY(-50%);
44-
transform: translateY(-50%);
45-
}
46-
47-
4838
.page__title, .page__subtitle {
4939
user-select: none;
5040
-moz-user-select: none;

index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44
{% include inline_style_index.html %}
55
<!--Title image will be set to display:none and used as a background image on the div below-->
6-
<div class="navigation__content container-fluid" data-image-type="responsive">
6+
<div class="navigation__content container-fluid">
77
<picture>
88
<source srcset="static/images/title_photo/title_glass_building_480x270.jpg 480w,
99
static/images/title_photo/title_glass_building_960x540.jpg 960w,
@@ -20,13 +20,12 @@
2020
static/images/title_photo/title_glass_building_1442x2562.jpg 1442w"
2121
media="(orientation: portrait)"
2222
sizes="100vw">
23-
<img class="responsive"
23+
<img class=""
2424
src="static/images/title_photo/title_glass_building_960x540.jpg"
25-
alt="Python Sprints Title Image"
26-
data-overlay="linear-gradient(180deg, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.8) 100%)">
25+
alt="Python Sprints Title Image">
2726
</picture>
2827

29-
<div class="navigation__title-container row">
28+
<div class="navigation__title-container row container-fluid">
3029
<div class="col-md-12">
3130
<h1 class="navigation__title">Python Sprints</h1>
3231
<h2 class="navigation__subtitle"><em>The World Needs Your Code</em></h2>

static/js/site.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ $(document).ready(function () {
1515
navigationButtonClose.on("click", closeNav);
1616
});
1717

18-
19-
function readDeviceOrientation() {
20-
21-
return window.matchMedia("(orientation: portrait)").matches;
22-
}
23-
2418
function stopBodyScrolling (bool) {
2519
/**
2620
* Required to stop body scrolling on iOS devices (safari ignores
@@ -73,45 +67,6 @@ function showCloseButton() {
7367
buttonCloseContainer.css("display", "inline");
7468
}
7569

76-
// Responsive background image constructor.
77-
class ResponsiveBackgroundImage {
78-
79-
constructor(element) {
80-
this.element = element;
81-
this.img = element.querySelector('.responsive');
82-
this.src = '';
83-
84-
this.img.addEventListener('load', () => {
85-
this.update();
86-
});
87-
88-
if (this.img.complete) {
89-
this.update();
90-
}
91-
}
92-
93-
update() {
94-
let src = typeof this.img.currentSrc !== 'undefined' ? this.img.currentSrc : this.img.src;
95-
let image = this.img;
96-
let overlay = image.getAttribute("data-overlay");
97-
if (overlay === null || overlay === undefined) {
98-
overlay = "";
99-
}
100-
101-
if (this.src !== src) {
102-
this.src = src;
103-
104-
this.element.style.backgroundImage = overlay + ', url("' + this.src + '")';
105-
}
106-
}
107-
}
108-
109-
// Create responsive background images.
110-
let elements = document.querySelectorAll('[data-image-type="responsive"]');
111-
for (let i=0; i<elements.length; i++) {
112-
new ResponsiveBackgroundImage(elements[i]);
113-
}
114-
11570
// Add active class to navigation elements in the navigation overlay and
11671
// footer on page load.
11772
$(setActiveLink());

0 commit comments

Comments
 (0)