Plugin Author
malihu
(@malihu)
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
(@hshah)
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
(@malihu)
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
(@hshah)
@malihu
Thank you very much! That was much easier than I thought it would be lol 🙂