Dev Diary Ep50 - Anchor Support

Hello again,

We’ve had a busy week working on MANY things, adding features, and fixing bugs. One much requested feature was anchors… and I’m pleased to say that Elements Beta 22 (due any minute now) will have full anchor support!

Watch the video to learn more about this awesome new feature, and stay till the end for a quick word about forms…

Thanks for your Feedback

We’re listening to all your feedback and working super hard to make Elements the perfect website builder.

Lots more great stuff to come!

See you soon,
Dan & Team Realmac.

9 Likes

Nicely done. It’s going to make me think a bit about how I use components, but that’s okay. This is a very elegant solution.

1 Like

I like how you have done this. Looks great!!

4 Likes

Thanks, was extra work to get it right, but totally worth it!

1 Like
  • What about a timing option?, seems a bit fast for my taste.
  • How will this be handled in regards to prefers reduced motion?

@Bill this is all standard web stuff…

No, Tailwind itself does not directly control the timing of the scroll. The scroll speed in smooth scrolling is controlled by the browser.

If you don’t want smooth-scroll on your website, you can remove the class from the Site Template file.

Alternatively, you can use the @media (prefers-reduced-motion: reduce) media query to disable or adjust smooth scrolling for users who prefer reduced motion.

html {
  scroll-behavior: smooth; /* Default smooth scroll */
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto; /* Disable smooth scrolling */
  }
}

This is a guiding light for Elements — Everything should be as open and configurable as possible :smiling_face:

This looks fantastic, well done.

I would like to point out that you can also use anchors by using a URL for the link with the form #anchor-name. When I first got the BETA I could not intuitively figure out how to use the popup (hadn’t watched the video yet) so I did it this way and it works flawlessly.

There is one more feature I would request that you consider for anchors and that is the ability to set an OFFSET. Why is this important? Because many times you have an anchor set on a component and when you activate it the browser scrolls up and the component is hidden under the navbar. By setting an offest you can ensure that the anchor is always visible when scrolled. Not essential to use anchors successfully but it does add a little polish to a site.

I have to say that your solution is great for cross page anchors, so easy to use. Fantastic.

1 Like

You can use the scroll padding and scroll margin CSS properties for this.

We don’t have controls on any component for those properties, but you can add the tailwind utility class to the Advanced->CSS Classes box. Use scroll-pt-6 to add 24px scroll padding to the top of your component.

Doing so should add the offset you’re looking for!

See the tailwind docs for more info and examples on scroll padding/margin: Scroll Padding - Tailwind CSS

1 Like

Anchor! Perfect! Enough said :smiley:

Forms. Yes! Yes! Yes! Can’t wait to see the rabbit you pull out of the hat!

Thank you for listening! I know it’s been tough and frustrating. But so so so so worth it to us!

Yes, that is an excellent suggestion and is an elegant way to solve this problem when it arises. I’ll give it a test run right now as I have a situation where I need some padding.

Mahalo!

So I gave this a spin and nothing happens. The anchor srolls to the exact same location whether the scroll-pt-6 is present or not. Possibly because I didn’t enter the class correctly in the custom CSS field. I have tried on numerous occasion to add classes to this field and never got it to work. Is there anything special with how the class is entered?

Hi @dan
Tailwind cannot directly control the speed or animation of a smooth scroll as it only provides the scroll-smooth utility for enabling smooth scrolling. However, you can use a simple JavaScript script with window.scrollTo to control the speed and animation duration of the scroll. Before I try and to avoid wasting time for nothing: is there an impossibility to use such a script with Elements?

This works for me scroll offset

If you want to control the scroll timing (and other options such as easing) then you could use something like the Smooth Scroll js library.

Simple enough to add to your project, just put the following in your project’s template:

<script src="https://cdn.jsdelivr.net/gh/cferdinandi/smooth-scroll@15/dist/smooth-scroll.polyfills.min.js"></script>

var scroll = new SmoothScroll('a[href*="#"]', {
	speed: 300
});

Note the speed option in the docs say this:

[speed] is a number representing the amount of time in milliseconds that it should take to scroll 1000px. Scroll distances shorter than that will take less time, and scroll distances longer than that will take more time. The default is 300ms.

Hope that help :slight_smile:

1 Like

@bon

works I set the speed slow for affect

1 Like

A lot of great information is being shared on the Forum, so I’m thinking it would be good to move some of this to the Elements Manual.

For example, I have created a page for Adjust Smooth Scroll Speed with the information that @bon posted. When other useful solutions come up, I will create pages for them in the Solutions area.

Let me know if you spot any other items here on the forum that you think should be in the Manual, and I’ll get them moved over!

1 Like

Hmm, will chat to @bon about this and see if we can figure out what’s going on!

scroll-mt-24. Works for me

Ah yes, of course :person_facepalming:

scroll-pt-24 is setting the padding (inside the component). You need/should use scroll-mt-24 to set the margin outside of the item.

I just tested this and can confirm it works here :+1:

You can also use an arbitrary value like this scroll-mt-[300px] if you want to set an exact pixel amount.

I did not use this I used scroll-pt-6, I tried the scroll-mt-24 and it works perfectly. Thanks.

I’m a happy camper now.