- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2023 01:45 PM
Hi!
So, I'm trying to use the "sticky" property in a CSS of a Service Portal Page, but it doesn't seem like it's supported by ServiceNow? Here's the effect (supported by most browsers) in question:
https://www.youtube.com/shorts/wdAkpswmnpo
So, I'm considering an alternative using javascript. But here's my question, how do I go around doing that if I can't manipulate the HTML of the page? And where would I put the code to work on that specific page? If I used an UI macro, where on the page would I call the macro? Only in a widget? I'd like to avoid call it by widget if possible, instead using the page itself.
Any other alternatives are very welcome.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2023 05:52 PM
I'm not sure how that would work as I don't think you can make a column scroll inside a container.
Of course, if you could make a column scroll inside a container, than it would be fair game.
Both a container and a column in a portal page are governed by Bootstrap styling.
I don't think it is worth messing with that.
But you can (and my advice would be that you should) take this to the widget level.
That is what I did.
I created a page with a container in it, which had (12 width) column in it, which had a widget in it which had as Body HTML template:
<div>
<p>A paragraph</p>
<p>A paragraph</p>
<p>A paragraph</p>
<p>A paragraph</p>
<p style="background-color: red; color: white; font-weight: bold; position: sticky; top: 1em;">This will stick</p>
<p>A paragraph</p>
<!--
the same paragraph many times, so that it makes the parent div scroll it's content.
-->
<p>A paragraph</p>
</div>
This is how I would do it and it would perfectly fit the Portal/AngularJS/Bootstrap paradigm.
Should you need to place/embed other widgets into the page, just do that inside this "master" widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2023 08:06 AM
You're most welcome and I appreciate marking the correct answer! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2023 10:07 AM - edited ‎12-23-2023 10:07 AM
So @-O- , I tried doing what I mentioned (a column inside a container) and it... sort of worked? Actually, it didn't work, but on the page editor it seems like it's working. I've recorded a video to show:
https://youtu.be/o2yHfXg8S9c
Same behavior no matter the browser I use.
I thought about your suggestion of embedding all of the widgets of the page inside a master widget, but that would probably be more trouble than it's worth for a simple effect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2023 12:48 PM
Perhaps the portal defines additional styles that make it not work in "real life"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2023 07:51 PM
While ServiceNow doesn't have native support for the position: sticky property within Service Portal pages, here are effective workarounds to achieve a similar sticky behavior:
1. Using position: fixed with Careful Positioning:
Apply position: fixed to the element you want to stick.
Adjust top, left, right, or bottom properties to position it within the viewport.
Important: Use z-index to control stacking order and prevent overlapping with other content.
Considerations:
Fixed elements can cover other content when scrolling.
Requires precise positioning to avoid unwanted behavior.
Example:
CSS
.sticky-element {
position: fixed;
top: 10px; /* Adjust as needed */
left: 0;
width: 200px;
z-index: 10; /* Ensure it's above other content */
}
2. Using JavaScript for Dynamic Stickiness:
Implement JavaScript code to track scroll position and dynamically adjust the element's position when a certain threshold is reached.
This provides more control and adaptability.
Example:
JavaScript
window.addEventListener('scroll', function() {
const stickyElement = document.querySelector('.sticky-element');
const scrollPosition = window.scrollY;
if (scrollPosition >= 100) { // Adjust threshold as needed
stickyElement.style.position = 'fixed';
stickyElement.style.top = '0';
} else {
stickyElement.style.position = 'static'; // Or 'relative', depending on your layout
}
});
3. Utilizing Theme Options for Fixed Headers/Footers:
If you need a fixed header or footer, explore theme options within ServiceNow.
Some themes offer built-in settings for fixed headers and footers.
4. Exploring Third-Party Libraries (If Allowed):
Consider using third-party sticky element libraries if your organization permits them.
Research compatibility and potential performance implications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2023 04:47 AM
While ServiceNow doesn't have native support for the position: sticky property...
Support for position sticky is not up to ServiceNow or Portal.