php - Running resize logo script on wordpress -
i'm trying implement custom logo shrink on website, i'm doing wrong , can't locate mistake. maybe can give small advice.
so did:
1.child theme style.css, functions.php, assets/js/my_shrinker.js
2.i added function 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.added code perform shrink when scrolling 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 "shrinkedlogo" class kad-header-left div, has css
.shrinkedlogoyo { display: block !important; position: absolute !important; left: 8% !important; top: 2px !important; width: 45px !important; height: 45px !important; }
but, well, ain't happening , i'm not getting error. can give me advice?
website http://arthome17.ru
the script "my-shrinker.js" not called correctly.
http://arthome17.ru/wp-content/themes/virtue_premium/assets/js/my-shrinker.js?ver=1.0.0
returns 404.
this because of get_template_directory_uri()
looking script in parent theme.
use get_stylesheet_directory_uri()
instead child theme.
hope helps.
edit since new error in console (syntaxerror: missing ( before formal parameters)
i suggest use addclass()
, removeclass()
properties , review syntax.
re-edit
if want script runs on page ready, you'll have write :
$ = 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"); } }); });
add jsfiddle
here live example of working script. luck !
Comments
Post a Comment