• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

adding jquery – missing something in this code?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › adding jquery – missing something in this code?

This topic is: not resolved

Tagged: jquery

  • This topic has 2 replies, 2 voices, and was last updated 7 years, 7 months ago by tussle.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • August 4, 2015 at 11:50 am #161401
    tussle
    Member

    Hi
    I have added jquery through a posted example, worked fine.

    I am trying to add another and followed all the steps exactly, but the js just won't work for a timeline. I tripled check the process .

    1. Added html and css (renders fine)

    2. Created .js directory and saved file as scroll.js - jquery is first word, then uploaded to js folder in child theme.

    jQuery(document).ready(function($) {

    $(window).scroll(function() {
    $('.container p').each(function() {
    var scrollTop = $(window).scrollTop(),
    elementOffset = $(this).offset().top,
    distance = (elementOffset - scrollTop),
    windowHeight = $(window).height(),
    breakPoint = windowHeight * 0.9;

    if (distance > breakPoint) {
    $(this).addClass("more-padding");
    }
    if (distance < breakPoint) {
    $(this).removeClass("more-padding");
    }
    });
    });

    });

    4. Added this to functions.php to enqueue

    //* Enqueue scroll rotating script
    add_action( 'wp_enqueue_scripts', 'enqueue_scroll' );
    function enqueue_scroll() {
    wp_enqueue_script( 'scroll', get_stylesheet_directory_uri() . '/js/scroll.js', array( 'jquery' ), '1.0.0', true );

    }

    The jquery effects do not work.

    Any ideas? Thank you.

    http://codepen.io/jm/pen/GlICH
    August 4, 2015 at 12:05 pm #161404
    Brad Dalton
    Participant

    Its hard to test because as soon as you embed code in webpage it breaks unless you wrap it in pre or code tags or better still, a Github Gist.

    What happens if you replace this

    jQuery(document).ready(function($) {
    

    with this:

    jQuery(function( $ ){

    ( Untested )


    Tutorials for StudioPress Themes.

    August 4, 2015 at 12:51 pm #161408
    tussle
    Member

    Thanks!
    Very strange, I replaced the one line with yours, it worked, then changed to what I had, that worked too. I don't know the issue. I cleared cache multiple times. But many thanks.

    I did not know about pre tags for code, appears fine in my browser but made note. I will test a few more code examples and hope they work. Thanks.

    jQuery(document).ready(function($) {
    
    $(window).scroll(function(){				 
    	$('.container p').each(function(){
        	var scrollTop     = $(window).scrollTop(),
            	elementOffset = $(this).offset().top,
           		distance      = (elementOffset - scrollTop),
    			    windowHeight  = $(window).height(),
    			    breakPoint    = windowHeight*0.9;
    
    			if(distance > breakPoint) {
    				$(this).addClass("more-padding");	
    			}  if(distance < breakPoint) {
    				$(this).removeClass("more-padding");	
    			}
    	});
    });
    
    });
    
    
    
    //* Enqueue scroll rotating script
    add_action( ‘wp_enqueue_scripts’, ‘enqueue_scroll’ );
    function enqueue_scroll() {
    wp_enqueue_script( ‘scroll’, get_stylesheet_directory_uri() . ‘/js/scroll.js’, array( ‘jquery’ ), ‘1.0.0’, true );
    
    }
    
    
  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble