Keyword

K2 Power Tip: Add Offset to Smooth Scroll Anchors - K2 Hack

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
9 years 10 months ago #145220 by Joe Campbell
Do you find that using anchors leaves some content hidden or cut off by your fixed top menu? I did, but I figured out how to fix this issue - Warning - it requires hacking your K2 component JavaScript file. Here's how...

File: components/com_k2/js/k2.js

Find: section labeled as "Smooth Scroll"

Add: "- 70" or whatever number works for your template fixed menu

Also: add a comment to remind you what/how you hacked the file

The result should be...
scrollTop: $K2(target).offset().top - 70 //HACK: added - 70 to compensate for fixed menu

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 10 months ago #145226 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 Power Tip: Add Offset to Smooth Scroll Anchors - K2 Hack
Joe,

We really need to talk about phrasing.
K2 Hack will make a lot of people (including my self) nervous about being hacked.

On the other note, this is not even a hack. You can override the js file.
Simply unset the file in the template and include your own copy.

Finally you can make this dynamic with jQuery 's height() function.
api.jquery.com/height/

You can dynamically calculate the offset with the use of that function.

Let me know if you need an example.

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
9 years 10 months ago #145231 by Joe Campbell
My apologies @Krikor, I did not mean to cause a scare by using the term "Hack."
My goal has always been to provide non-coders such as myself the tools to take their K2 website to the next level...that's all.

I did not know you can override JS files.

I just tried it, but it did not work. I placed the K2 JavaScript file here...
/templates/MYTEMPLATE/html/com_k2/js/k2.js

But the following file is still being rendered:
/components/com_k2/js/k2.js?v2.6.7&sitepath=/

What am I doing wrong?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 10 months ago #145238 by Krikor Boghossian

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
9 years 10 months ago #145242 by Joe Campbell
Thanks @Krikor

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum