Add Sticky Buttons for Improved UX in SuiteCommerce

Sticky buttons enhance user experience by remaining visible during scrolling. Learn how to implement them in SuiteCommerce.

·2 min read·View Oracle Docs

Sticky buttons are anchor elements that retain their position on a page as users scroll through content. This feature is especially valuable on lengthy pages where a prominently-placed call-to-action button helps guide users to subsequent pages. A practical example is the Proceed to Checkout button, which remains fixed on the screen while users explore items in the shopping cart.

Implementing sticky buttons can be effectively accomplished using the jQueryExtras/jQuery.scStickyButton.js plugin provided by Oracle NetSuite. Below is a step-by-step guide on how to add sticky buttons to your web page for enhanced interaction:

Steps to Add a Sticky Button

1. Update the View

1.1 Add the Plugin as a Dependency

Start by including jQuery.scStickyButton.js as a dependency in your view:

css
1define('MyCompany.MyExtension.MyModule.View',
2[
3 'mycompany_myextension_mymodule.tpl',
4 'MyCompany.MyExtension.MyModule.SS2Model',
5 'Backbone',
6 'jQuery.scStickyButton'
7 ],
8function (
9 mycompany_myextension_mymodule_tpl,
10 MyModuleSS2Model,
11 Backbone,
12 jQueryscStickButton
13) {
14 // ...
15});

1.2 Create a Listener

Next, create a listener to initialize the plugin. This is done by defining the showContent() method:

css
1showContent: function showContent () {
2 var self = this;
3 this.application.getLayout().showContent(this).done(function () {
4 self.initPlugins();
5 });
6 }

1.3 Define initPlugins() Method

Define the initPlugins() method to make a button element sticky. This method utilizes jQuery to locate elements with the sticky attribute and executes scStickyButton() on them:

css
initPlugins: function initPlugins () {
this.$el.find('[data-action="sticky"]').scStickyButton();
}

2. Update the Template

2.1 Define the Sticky Button Element

In your HTML template, define the element you want to make sticky by adding a custom data attribute:

css
<a class="some-button-class" data-action="sticky" href="some-path" data-hashtag="#">Sticky button!</a>

The attribute data-action="sticky" designates the button as sticky. Additional attributes can be included as necessary.

3. Test the Extension

3.1 Local Server Login

Finally, log in to your local server to verify that the sticky button appears at the top of the page, staying visible while scrolling down.

Key Consideration

Note: The jQuery.scStickyButton.js plugin activates only when the user’s screen width is less than 768 pixels. On larger screens, buttons will stay fixed in their original positions.

Key Takeaways

  • Sticky buttons enhance user navigation on long pages.
  • Use jQuery.scStickyButton.js for implementation in SuiteCommerce projects.
  • Ensure adaptive operation based on screen size for optimal user experience.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Do sticky buttons in SuiteCommerce require enabling a feature flag?
No, you do not need to enable a feature flag. You only need to implement the `jQueryExtras/jQuery.scStickyButton.js` plugin in your view.
What happens to sticky buttons on screens wider than 768 pixels?
On screens wider than 768 pixels, the sticky buttons will stay in their original positions and not be anchored during scrolling.
How can I designate a button as sticky in my template?
You can designate a button as sticky by adding the `data-action="sticky"` attribute to the element in your HTML template.
Is the `jQuery.scStickyButton.js` plugin compatible with all SuiteCommerce editions?
The article does not specify compatibility with all SuiteCommerce editions; it focuses on the implementation within SuiteCommerce projects.
Source: Add a Sticky Button Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Commerce

View all Commerce articles →