Skip to content

Instantly share code, notes, and snippets.

@divienginesupport
divienginesupport / basic-jquery.js
Last active March 30, 2021 18:12
Sample jQuery that can be added to Divi
<script type="text/javascript">
jQuery(document).ready(function( $ ) { // When jQuery is ready
function check_from_top_de(){ // Create our function
var scroll = $(window).scrollTop(); // Check scroll distance
if (scroll >= 300) { // If it is equal or more than 300 - you can change this to what you want
$("#your-target-element").addClass("class-to-be-added"); // Add custom class to body
} else {
$("#your-target-element").removeClass("class-that-we-added"); // When scrolled to the top, remove the class
@divienginesupport
divienginesupport / fixed-header-on-scroll.css
Last active March 30, 2021 17:03
CSS for Fixed Header on scroll
.fixed-header {
position: fixed;
width: 100%;
-webkit-animation: fadein 1s ease-in-out;
-moz-animation: fadein 1s ease-in-out;
animation: fadein 1s ease-in-out;
}
@keyframes fadein {
from { opacity: 0; }
@divienginesupport
divienginesupport / fixed-blurb-modules.js
Last active March 31, 2021 06:56
Example 2: Making fixed blurb modules appear and disappear on scroll
<script>
// Run after document has loaded...
jQuery(document).ready(function($){
// Do something on waypoint...
$('#module-one').waypoint(function(){ //Once we have scrolled to the first module, we execute our function
$('#one').fadeIn(); // Fade in the first blurb
$('#two').fadeOut(); // Fade out the second blurb in case the user is scrolling up
}, {offset: '25%'}); // This checks to see if #module-one element is at least 25% scrolled into view
$('#module-two').waypoint(function(){ //Once we have scrolled to the second module, we execute our function
$('#two').fadeIn(); // Fade in the second blurb
@divienginesupport
divienginesupport / header-color-swap.js
Last active March 31, 2021 07:14
This adds a class to the Divi header that changes the background color on scroll
<script type="text/javascript">
jQuery(document).ready(function( $ ) { // When jQuery is ready
function check_from_top_de(){ // Create our function
var scroll = $(window).scrollTop(); // Check scroll distance
if (scroll >= 300) { // If it is equal or more than 300 - you can change this to what you want
$("#main-header").addClass("change-bg-color"); // Add custom class to body which will change the color
} else {
$("#main-header").removeClass("change-bg-color"); // When scrolled to the top, remove the class which changes the color back
@divienginesupport
divienginesupport / header-color-swap.css
Created March 31, 2021 07:16
This is the CSS that is added by the header-color-swap.js file
.change-bg-color {
background-color: springGreen!important;
}
@divienginesupport
divienginesupport / icon-add-to-cart-functions.php
Last active April 1, 2021 19:12
Add quantity field and add-to-cart icon button on product loop
//Setting up Woocommerce "Add to Cart" icon button and adding the quantity field.
//Add-to-Cart Button
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );
//Change the Add to Cart text to basket Icon
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( '&#xe013;', 'woocommerce' );
}
@divienginesupport
divienginesupport / icon-add-to-cart-style.css
Last active August 3, 2021 10:48
CSS to style Divi WooCommerce Add-To-Cart Icon Button
/*CSS to make sure the Quantity and Add to cart button are next to each other*/
.product .cart {
display: flex;
flex-flow: row nowrap;
justify-content: center;
margin-top: 10px;
}
.product .cart button[type="submit"] {
@divienginesupport
divienginesupport / woocommerce-title-price-overlay.js
Last active January 20, 2022 11:52
jQuery to add Title and Price Overlay
jQuery(document).ready(function($) {
function moveproddetails() {
var shop_module = $('.divi-engine-custom-overlay'),
shop_item = shop_module.find('li.product');
shop_item.each(function() { // Runs through each loop item in the shop
var product_title = $(this).find('.woocommerce-loop-product__title'), // Finds the Product Title
product_price = $(this).find('span.price'), // Finds the Product Price
product_overlay = $(this).find('.et_overlay'); // Finds the Divi Overlay
product_title.detach(); // Detaches the Product Title
product_price.detach(); // Detaches the Product Title
@divienginesupport
divienginesupport / woocommerce-title-price-overlay.css
Created May 7, 2021 06:14
CSS to add Title and Price Overlay
<style>
/* Hover Price and Title in overlay */
.et_overlay .woocommerce-loop-product__title,
.et_overlay .price,
.et_overlay .loop-title-item,
.et_overlay .loop-title-price {
text-align: center; /* Centers the Title and Price */
position: absolute;
@divienginesupport
divienginesupport / Slick-Divi-Integration.html
Last active May 24, 2021 21:09
Slick.js Divi Integration Code
<link rel="stylesheet" type="text/css" href="/wp-content/themes/[your child theme folder]/slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="/wp-content/themes/[your child theme folder]/slick/slick-theme.css"/>
<script type="text/javascript" src="/wp-content/themes/[your child theme folder]/slick/slick.min.js"></script>