javascript - Function is undefined -


i new javascript, here deal:

i'm trying implement reading-position-indicator wordpress theme. therefore hooked div directly behind footer near script-tags, cause position-bar should stick on bottom of screen. tried implement kind of custom.js, should vary width of position-indicator depending on how far user has scrolled down. fails, , don't know why, aware fact cardinal fault i've made based on lacking experience js.

evertime console sends "reference error: xyz not defined"

here code, can inspected on jsfiddle (, although might little bit useless, cause script runs in wordpress environment, can't emulated there).

html/php-hook markup:

add_action('wp_footer', 'tg_wp_footer'); function tg_wp_footer() {  if ( is_singular() ) echo '<div id="reading-position-indicator"></div>'; }  

js-markup:

if( '"is_singular && reading_indicator"' ){     var reading_content = $the_post.find( '.entry' );     if( reading_content.length > 0 ){          reading_content.imagesloaded(function() {             var content_height  = reading_content.height();                 window_height   = $window.height();              $window.scroll(function() {                 var percent         = 0,                     content_offset  = reading_content.offset().top;                     window_offest   = $window.scrolltop();                  if (window_offest > content_offset) {                     percent = 100 * (window_offest - content_offset) / (content_height - window_height);                 }                 jquery('#reading-position-indicator').css('width', percent + '%');             });         });     } } 

css-markup:

#reading-position-indicator { display: block; height: 4px; position: fixed; bottom: 0; left: 0; background: #ff8500; width: 0; z-index: 9999; max-width: 100%; } 

https://jsfiddle.net/cn49ubr6/1/

the bar should appear on blog-post, therefore tried use "is_singular". how define avoid referenceerror? atm console says "$the_post" not defined. before that, when tried without '" '" in first line, got error is_singular not defined.

kind regards!

jordan, right. after inspecting object element dev tools (chrome, firebug, firefox nightly) found firebug best solution events. firstly had change declarations, since migrated bar theme mine. html markup totally differs other theme. after struggled 3 jquery-plugins, necessary thing work, cause used in javascript. last not least had find right html elements calculation. seems work, test further.

i write, cause wanted know why console gives me error undefined when write

if (is_singular ()) {  

whereas if write

if ('is_singular()') { 

the whole thing gets alive?

thank you! :-)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -