Throttle or Delay JavaScript Functions When Window is Resized [code snippet]

Underscore.js has a popular method for throttling and debouncing functions to prevent them from firing multiple times when a window is resized. I found this delay function that works for times when you don’t need to load the entire underscore library to achieve a similar effect.

Continue Reading

Category: Code Snippets

How to Change Favicon with JavaScript

This code comes in handy when you don’t have access to the head of the page and need to change the favicon. (function() { var link = document.querySelector(“link[rel*=’icon’]”) || document.createElement(‘link’); link.type = ‘image/x-icon’; link.rel = ‘shortcut icon’; link.href = ‘https://yourdomain.com/favicon.ico’; document.getElementsByTagName(‘head’)[0].appendChild(link); })();  

Continue Reading

Category: Code Snippets

How to Fire a jQuery Function When the Page is Loaded and Resized

When building responsive websites you often want to run a script when the page loads. But when you resize the window the layout breaks. You can use the on method to run your code if the page loads or has been resized. // run on page load and when the window is resized $(window).on(“load resize”,function(e){… Read more »

Continue Reading

Category: Code Snippets

Web Font Weight and Style Mixin [Code Snippet]

If you are using Google Fonts or a custom web font, you probably are writing different font weights and styles. These mixins combine the two to make it really easy to update a global font style in your stylesheet.

Continue Reading

Category: Code Snippets

How to Visually See What Your jQuery Selection is Selecting

I was recently working on form validation and wanted to mark a.form-group as successful if it contained a particular icon inside the label. The icon was set using PHP depending if the data existed in the database. I was writing .prev() and .parent() to try and select the wrapping .form-group but it wasn’t working and… Read more »

Continue Reading

Category: Code Snippets / Tutorials

How to Prevent One Word Lines (widow orphan) In Website Paragraphs

I am often adding padding to the left and right of paragraphs to force copy down to prevent one word on a line. Or even worse, I add <br> to a word on the line above to prevent the word by itself. But this causes issues with responsive design because the <br> changes position breaking… Read more »

Continue Reading

Category: Code Snippets

What are the Open Sans CSS Font Weights?

I often want to use different font weights for Open Sans and so am adding them here for quick reference later. Open Sans light font-weight: 300; regular font-weight: 400; semi-bold font-weight: 600; bold font-weight: 700; extra-bold font-weight: 800;

Continue Reading

Category: Common Questions

How to Trigger HubSpot Popup Form on Button Click or Page Load

HubSpot provides the ability to display a pop up form with various triggers (exit intent, after 7 seconds, etc.) But what if you want to show it immediately or when a button is clicked? Below is some javascript to help achieve this functionality. How to use this script Create pop up form Set targeting to… Read more »

Continue Reading

Category: Code Snippets

Open All Links to PDF files in a New Window

This finds all of the links pointing to PDF files and opens them in a new window. If you are using Chrome, you will need to enable popups for this to work. $(“a[href$=’.pdf’]”).each(function () { window.open($(this).attr(‘href’),”_blank”); });  

Continue Reading

Category: Code Snippets

How to Add a Featured Tag with Text Over an Image

In this tutorial I will show you how to place a featured tag over an image using CSS3 ::before pseudo elements. A common use case for this is eCommerce where you might want to visually show a product is featured, on sale, or out of stock. Since your products are displayed dynamically using a database,… Read more »

Continue Reading

Category: Tutorials