简体   繁体   中英

JavaScript doesn't work until I resize the window then resize it back

I've implemented JavaScript on wordpress and it only works after i re-size the window from the original size to a different size then back to the original size. I don't understand why it just doesn't work from the start?

Here is the script in the head

<script type="text/javascript" src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.js"></script>
<script type="text/javascript" src="/wp-content/themes/dw-minion/assets/css/jstick/jquery.stickem.js"></script>
<script type="text/javascript">
  jQuery(document).ready(function($) {
    $('.container').stickem();
  });
</script>

The place the script is used in content.php inside the body

<div class="container">
  <div class="row stickem-container">
    <div class="content">
      <div class="entry-content"> 
        <a href="<?php the_permalink(); ?>"><?php the_content(); ?></a>
      </div>
    </div>
    <div class="aside stickem">
      <div class="sharepinterest">
        <?php echo get_simple_local_avatar( $id_or_email, $size, $default, $alt ); ?>
      </div>
    </div>
  </div>
</div>

Scripts should be enqueued for execution using wp_enqueue_script in functions.php file of your theme. This is the preferred method to enqueue scripts and style.

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Perhaps this might be preventing your script from being executed right from start.

Would prefer to comment but don't have the reputation, please check here.

Running javascript after page is fully rendered

I had this issue prevsiouly as a script was being triggered before the page was rendered. Resizing the window, zooming in and out and also bringing up the chrome element inspector reszied the issue div.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM