Title: Scroll Condition &#8211; Current Position
Last modified: April 19, 2020

---

# Scroll Condition – Current Position

 *  Resolved [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/)
 * I’ve added JS to my footer after reading posts on here, and that works perfectly(
   scrolls a CPT down to a CSS # with an additional offset of 55px).
 * However, that is quite annoying when the user refreshes the page because Chrome
   usually returns to the same view, but with the jQuery in place, it moves away
   from that.
 * Is there a way to only execute the jQuery if the page is right at the top?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [malihu](https://wordpress.org/support/users/malihu/)
 * (@malihu)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12697456)
 * Hi,
 * I’m not sure which js you added in your footer. Can you post you page/site URL
   so I can check what happens?
 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12697633)
 * Hi,
 * I can’t provide a link because I’m playing around in a locked down staging environment,
   but here is the script I added:
 *     ```
       <script>
           (function($){
               $(window).on("load",function(){
                   $.mPageScroll2id("scrollTo","#content-title",{
                       offset:55
                   });
               });
           })(jQuery);
       </script>
       ```
   
 * This works fine in the sense that every time the page loads, it scrolls to the
   specified ID + the offset.
 * However, I’m wondering if there is a way to make it run only when the page is
   at the top? In Chrome, when refreshing a page, it reloads to the same position
   it was in when refreshed.
 * If I’m towards the bottom, the script causes it to scroll up to the ID, and if
   I’m at the top, it scrolls down to the ID.
 * I don’t want it to scroll up if I’m more than 50% down the page. If it’s reloaded
   anywhere between 0% and 50%, I want the script to run and do its thing.
 * I hope that makes sense 🙂
 *  Plugin Author [malihu](https://wordpress.org/support/users/malihu/)
 * (@malihu)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12698335)
 * I see. To trigger the `scrollTo` method only when the page is at the very top,
   try this:
 *     ```
       <script>
           (function($){
               $(window).on("load",function(){
                   if($(window).scrollTop() == 0){
                       $.mPageScroll2id("scrollTo","#content-title",{
                           offset:55
                       });
                   }
               });
           })(jQuery);
       </script>
       ```
   
 * To trigger the method only when the page is scrolling is less than 50%, try this:
 *     ```
       <script>
           (function($){
               $(window).on("load",function(){
                   var scrollPCT=Math.round(100 * $(window).scrollTop() / ($(document).height() - $(window).height()));
                   if(scrollPCT <= 50){
                       $.mPageScroll2id("scrollTo","#content-title",{
                           offset:55
                       });
                   }
               });
           })(jQuery);
       </script>
       ```
   
 * Hope this helps 🙂
 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12698404)
 * [@malihu](https://wordpress.org/support/users/malihu/)
 * Thank you very much! That was much easier than I thought it would be lol 🙂
 *  Plugin Author [malihu](https://wordpress.org/support/users/malihu/)
 * (@malihu)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12701816)
 * You’re welcome 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Scroll Condition – Current Position’ is closed to new replies.

 * ![](https://ps.w.org/page-scroll-to-id/assets/icon-256x256.png?rev=1401043)
 * [Page scroll to id](https://wordpress.org/plugins/page-scroll-to-id/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/page-scroll-to-id/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/page-scroll-to-id/)
 * [Active Topics](https://wordpress.org/support/plugin/page-scroll-to-id/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/page-scroll-to-id/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/page-scroll-to-id/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [malihu](https://wordpress.org/support/users/malihu/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/scroll-condition-current-position/#post-12701816)
 * Status: resolved