Key dates
Project started on 2024-07-17
First QA planned for 2024-07-31
Lessons learnt
site breakpoints
Both Astra and Elementor are set to have these breakpoints: – tablet 1023px and phone 544px.
Elementor input field
- Input fields with pencil icon now support custom setting, for example it is acceptable to input likes this
min(50%, 652px). In this case, the max-width is 652px as it will select the minimum value from either 50% or 652px.
Anchor link jump error
- Due to lazy loading of images, the anchor link could jump to a wrong positiion. The jQuery animation is used to solve this problem. Ref: stackoverflow.com
/**
* Anchor link to Enquire Form
* Animation to solve wrong position jump.
*/
jQuery("body").on("click", ".cu-menu-enquire a.menu-link", function (e) {
let targetSelector = this.hash;
let $target = jQuery(targetSelector);
jQuery("html, body").animate(
{
scrollTop: $target.offset().top,
},
{
duration: 1800,
step: function (now, fx) {
let newOffset = $target.offset().top;
if (fx.end !== newOffset) fx.end = newOffset;
},
}
);
});
- To enqueue the file cu-script.js which contains the above code, add the following lines to functions.php. Note that jquery is the dependency.
function cu_enqueue_script() {
wp_enqueue_script( 'cu-script', get_stylesheet_directory_uri() . '/cu-script.js', array('jquery'), CHILD_THEME_ASTRA_CHILD_VERSION, true );
}
add_action( 'wp_enqueue_scripts', 'cu_enqueue_script', 15 );
Remove url hash tag after jumping to the anchor position
For anchor jump to a position on the same page, the URL will have a # tag at the end, to remove this hash tag, add the below script to the jQuery for jump error above.
/** remove hash tag after scrolling to position
the hash tag will be removed 1.9s after the jump,
this script should be included into the above jQuery for jump error
*/
setTimeout(() => {
const currentURL = window.location.href;
const urlWithoutHash = currentURL.split('#')[0];
window.history.replaceState({}, document.title, urlWithoutHash);
}, 1900);
Auto close of mobile nav panel
- As the Enquire Now makes the page to scroll down on the same page, the mobile nav panel could not close itself. A JS script is required to solve the problem.
/**
* Hide mobile menu panel after Enquire Now menu item is clicked
*/
const popup = document.querySelector("#ast-mobile-popup");
const mobileEnqLink = document.querySelector(
"#ast-mobile-popup .cu-menu-enquire"
);
const burgerIcon = document.querySelector("button.menu-toggle");
mobileEnqLink.addEventListener("click", (event) => {
event.preventDefault();
popup.classList.remove("active");
popup.classList.remove("show");
burgerIcon.style.display = "flex";
});
Disable Large Image Scaling
WordPress 5.3 introduced image scaling for large images over 2560px on the longest edge.
This means if you upload a 5000px by 3000px it’ll be scaled down to 2560px by 1536px. This is great for most sites, especially for users who upload large files and may be unaware of how large the file is.
Increase WordPress Image Scaling Threshold
<?php
// Increase the image resize threshold to 4000px on the longest edge
function smartwp_big_image_size_threshold( $threshold ) {
return 4000;
}
add_filter( 'big_image_size_threshold', 'smartwp_big_image_size_threshold', 999, 1);
Disable WordPress Image Scaling
// Disable WordPress' automatic image scaling feature
add_filter( 'big_image_size_threshold', '__return_false' );
The “Play Full Film” Button
By clicking the ‘Play Full Film’ button, a lightbox will come up to auto play a video from Vimeo. As this video is set to autoplay, it cannot be downloaded first during page load. Therefore, the iframe for the video is constructed (by JS) only after the button is clicked.
When the Close button or anywhere on the screen is clicked, both the lightbox and the video iframe are removed.
The ‘Close’ button on the lightbox is built using only CSS – very efficient.
The html, css and JS can be find in the project folder MJ1900:/03-1ming/53/12/play-full-film-button.html
