Running script resizing logo in wordpress

I am trying to implement a custom logo on a website, but I am doing something wrong and cannot find the error. Maybe you can give a little advice.

So what I have already done:

1.Child theme with style.css, functions.php, assets / js / my_shrinker.js

2. I added a function to load my-shrinker.js in functions.php

function shrinker() {
    wp_enqueue_script( 'my_shrinker', get_stylesheet_directory_uri().'/assets/js/my_shrinker.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'shrinker' );

3.Remove this code to perform scroll compression in my-shrinker.js

function my_shrinker() { 
window.addEventListener('scroll', function(event){
        var distanceY = window.pageYOffset || document.documentElement.scrollTop,
            shrinkOn = 300,
            d = document.getElementsByTagName("kad-header-left");
        if (distanceY > shrinkOn) {
            d.className += " shrinkedlogoyo";
        } else {
            d.classList.remove("shrinkedlogoyo");
        }
        })
}

the script should add the "shrinkedlogo" class to the kad-header-left div div that this css has

.shrinkedlogoyo { display: block !important; position: absolute !important; left: 8% !important; top: 2px !important; width: 45px !important; height: 45px !important; }

But, this does not happen, and I do not get any errors. Can you give me some good advice?

Website http://arthome17.ru

+4
source share
1

script "my-shrinker.js" .

http://arthome17.ru/wp-content/themes/virtue_premium/assets/js/my-shrinker.js?ver=1.0.0

404.

- get_template_directory_uri(), script .

get_stylesheet_directory_uri() .

, .

(SyntaxError: ( )

addClass() removeClass() .

RE-EDIT

, script , - :

$ = jQuery.noConflict();
$(document).ready(function() { 
    window.addEventListener('scroll', function(event){
        var distanceY = window.pageYOffset || document.documentElement.scrollTop,
            shrinkOn = 300;
        if (distanceY > shrinkOn) {
            $(".kad-header-left").addClass("shrinkedlogoyo");
        } else {
            $(".kad-header-left").removeClass("shrinkedlogoyo");
        }
    });
});

jsfiddle

script. !

+3

Source: https://habr.com/ru/post/1659938/


All Articles