ScrollBar - Documentation | www.HtmlElements.com

Overview

A scroll bar is a numeric control used to select a numeric value from a range of values by moving a thumb along a track or by clicking on the track itself. It is typically used in conjucntion with the listbox and dropdown elements to allow scrolling through the items. The user can change the value by clicking in the tank area if it is set as an input element.

Getting Started with ScrollBar Web Component

Smart UI for Web Components is distributed as smart-webcomponents NPM package. You can also get the full download from our website with all demos from the Download page.

Setup the ScrollBar

Smart UI for Web Components is distributed as smart-webcomponents NPM package

  1. Download and install the package.

    npm install smart-webcomponents

  2. Once installed, import the ScrollBar module in your application.

    <script type="module" src="node_modules/smart-webcomponents/source/modules/smart.scrollbar.js"></script>

  3. Adding CSS reference

    The smart.default.css CSS file should be referenced using following code.

    <link rel="stylesheet" type="text/css" href="node_modules/smart-webcomponents/source/styles/smart.default.css" />

  4. Add the ScrollBar tag to your Web Page

    <smart-scroll-bar id="scrollbar"></smart-scroll-bar>

  5. Create the ScrollBar Component

    	<script type="module">
    		Smart('#scrollbar', class {
    			get properties() {
    				return {value: 50}
    			}
    		});
    	</script>	   
    		

    Another option is to create the ScrollBar is by using the traditional Javascript way:
    	const scrollbar = document.createElement('smart-scroll-bar');
    
    	scrollbar.disabled = true;
    	document.body.appendChild(scrollbar);
    		

    Smart framework provides a way to dynamically create a web component on demand from a DIV tag which is used as a host. The following imports the web component's module and creates it on demand, when the document is ready. The #scrollbar is the ID of a DIV tag.

    	import "../../source/modules/smart.scrollbar.js";
    
    	document.readyState === 'complete' ? init() : window.onload = init;
    
    	function init() { 
    		const scrollbar = new Smart.ScrollBar('#scrollbar', {value: 50});
    	}
    	

  6. Open the page in your web server.

Appearance

The scroll bar can be horizontal or vertical. This could be set via orientation property.

 <smart-scroll-bar orientation="vertical"></smart-scroll-bar>

Demo

Behavior

Scrollbar's range is defined by min and max properties.

When scrollbar's button is pressed, the value is increased/decreased by value, defined in step property.

If the user press the left mouse button in the area between a scrollbar button and thumb the value is increased/decreased by the value of largeStep property.

 <smart-scroll-bar min="0" max="100" step="10" large-step="20"></smart-scroll-bar>

Demo

Styling

Smart.ScrollBar uses the following CSS variables for styling:

  • --smart-scroll-button-size: used to set the size of the scroll buttons. Default value is 16px.

Create, Append, Remove, Get/Set Property, Invoke Method, Bind to Event


Create a new element:
	const scrollbar = document.createElement('smart-scroll-bar');
	

Append it to the DOM:
	document.body.appendChild(scrollbar);
	

Remove it from the DOM:
	scrollbar.parentNode.removeChild(scrollbar);
	

Set a property:
	scrollbar.propertyName = propertyValue;
	

Get a property value:
	const propertyValue = scrollbar.propertyName;
	

Invoke a method:
	scrollbar.methodName(argument1, argument2);
	

Add Event Listener:
	const eventHandler = (event) => {
	   // your code here.
	};

	scrollbar.addEventListener(eventName, eventHandler);
	

Remove Event Listener:
	scrollbar.removeEventListener(eventName, eventHandler, true);
	

Using with Typescript

Smart Web Components package includes TypeScript definitions which enables strongly-typed access to the Smart UI Components and their configuration.

Inside the download package, the typescript directory contains .d.ts file for each web component and a smart.elements.d.ts typescript definitions file for all web components. Copy the typescript definitions file to your project and in your TypeScript file add a reference to smart.elements.d.ts

Read more about using Smart UI with Typescript.

Getting Started with Angular ScrollBar Component

Setup Angular Environment

Angular provides the easiest way to set angular CLI projects using Angular CLI tool.

Install the CLI application globally to your machine.

npm install -g @angular/cli

Create a new Application

ng new smart-angular-scrollbar

Navigate to the created project folder

cd smart-angular-scrollbar

Setup the ScrollBar

Smart UI for Angular is distributed as smart-webcomponents-angular NPM package

  1. Download and install the package.
    npm install smart-webcomponents-angular
  2. Once installed, import the ScrollBarModule in your application root or feature module.

    app.module.ts

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { ScrollBarModule } from 'smart-webcomponents-angular/scrollbar';
    
    import { AppComponent } from './app.component';
    
    @NgModule({
        declarations: [ AppComponent ],
        imports: [ BrowserModule, ScrollBarModule ],
        bootstrap: [ AppComponent ],
    	entryComponents: [ AppComponent ]
    })
    
    export class AppModule { }
    	

  3. Adding CSS reference

    The following CSS file is available in ../node_modules/smart-webcomponents-angular/ package folder. This can be referenced in [src/styles.css] using following code.

    	@import 'smart-webcomponents-angular/source/styles/smart.default.css';

    Another way to achieve the same is to edit the angular.json file and in the styles add the style.

    	"styles": [
    		"node_modules/smart-webcomponents-angular/source/styles/smart.default.css"
    	]
    	
  4. Example


    app.component.html

     
    <section>
        <div>
             <h2>Scrollbars let users to select values by moving the scrollbar thumb.</h2>
            <div class="module">
                <p>Scrollbars are ideal components for adjusting settings that reflect intensity
                    levels, such as volume, brightness, or color saturation.</p>
            </div>
        </div>
    </section>
    <section id="continuousSliders">
         <h2>Continuous scrollbar</h2>
        <div class="module">
            <p>Use continuous scrollbars for subjective settings that do not require
                a specific value for the user to make meaningful adjustments.</p>
        </div>
        <div class="module continuousSliderLight">
            <table>
                <tr>
                    <td>
                        <p>Normal</p>
                    </td>
                    <tr/>
                    <tr>
                        <td>
                            <smart-scroll-bar #scrollbar></smart-scroll-bar>
                        </td>
                        <tr/>
                        <tr>
                            <td>
                                <smart-scroll-bar #scrollbar2 max="100" value="50"></smart-scroll-bar>
                            </td>
                            <tr/>
                            <tr>
                                <td>
                                    <smart-scroll-bar #scrollbar3 max="100" value="100"></smart-scroll-bar>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p>Disabled</p>
                                </td>
                                <tr/>
                                <tr>
                                    <td>
                                        <smart-scroll-bar #scrollbar4 disabled max="100"></smart-scroll-bar>
                                    </td>
                                    <tr/>
                                    <tr>
                                        <td>
                                            <smart-scroll-bar #scrollbar5 disabled max="100" value="50"></smart-scroll-bar>
                                        </td>
                                        <tr/>
                                        <tr>
                                            <td>
                                                <smart-scroll-bar #scrollbar6 disabled max="100" value="100"></smart-scroll-bar>
                                            </td>
                                        </tr>
            </table>
        </div>
    </section>
    <section id="verticalSliders">
         <h2>Orientation</h2>
        <div class="module">
            <p>smartScrollBar can be horizontal or vertical depending on the orientation
                property.</p>
        </div>
        <div class="module">
            <div>
                <smart-scroll-bar #scrollbar7 max="100" value="50"></smart-scroll-bar>
                <br/>
                <br/>
                <smart-scroll-bar #scrollbar8 orientation="vertical" max="100" value="75"></smart-scroll-bar>
            </div>
            <br/>
            <p>Vertical scrollbars</p>
        </div>
    </section>
    <section id="demoSliders">
         <h2>Demo</h2>
        <div class="module">
            <p>ScrollBars are controls that are used for adjusting values precisely.</p>
        </div>
        <div class="module media-controls">
            <div>
                 <h2>Volumes</h2>
                <div>
                     <h3>Media volume</h3>
                    <div id="mediaControl" class="controls"> <i class="material-icons">&#xE04D;</i>
                        <smart-scroll-bar #scrollbar9 id="mediaSlider"
                        max="100" value="25"></smart-scroll-bar>
                    </div>
                </div>
                <div>
                     <h3>Alarm volume</h3>
                    <div id="alarmControl" class="controls"> <i class="material-icons">&#xE855;</i>
                        <smart-scroll-bar #scrollbar10 id="alarmSlider"
                        max="100" value="50"></smart-scroll-bar>
                    </div>
                </div>
                <div>
                     <h3>Ring volume</h3>
                    <div id="ringControl" class="controls"> <i class="material-icons">&#xE7F4;</i>
                        <smart-scroll-bar #scrollbar11 id="volumeSlider"
                        max="100" value="75"></smart-scroll-bar>
                    </div>
                </div>
            </div>
        </div>
        <div class="module power-controls">
            <div>
                 <h2>Battery Saver Mode</h2>
                <div>
                     <h3>Low battery alert on <b id="lowBatteryAlert">15</b> %</h3>
                    <div id="mediaControl" class="controls"> <i class="material-icons">&#xE8B2;</i>
                        <smart-scroll-bar #scrollbar12 id="lowBatterySlider"
                        max="100" value="15" scale-type="integer"></smart-scroll-bar>
                    </div>
                </div>
                <div>
                     <h3>Power saver mode active on <b id="powerSaver">50</b>%</h3>
                    <div id="alarmControl" class="controls"> <i class="material-icons">&#xE19C;</i>
                        <smart-scroll-bar #scrollbar13 id="powerSaverSlider"
                        max="100" value="50" scale-type="integer"></smart-scroll-bar>
                    </div>
                </div>
            </div>
        </div>
    </section>
    		

    app.component.ts

     
    import { Component, ViewChild, OnInit, AfterViewInit } from '@angular/core';
    import { ScrollBarComponent } from 'smart-webcomponents-angular/scrollbar';
    
    
    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
    	styleUrls: ['./app.component.css']
    })
    
    export class AppComponent implements AfterViewInit, OnInit {	
    	@ViewChild('scrollbar', { read: ScrollBarComponent, static: false }) scrollbar: ScrollBarComponent;
    	@ViewChild('scrollbar2', { read: ScrollBarComponent, static: false }) scrollbar2: ScrollBarComponent;
    	@ViewChild('scrollbar3', { read: ScrollBarComponent, static: false }) scrollbar3: ScrollBarComponent;
    	@ViewChild('scrollbar4', { read: ScrollBarComponent, static: false }) scrollbar4: ScrollBarComponent;
    	@ViewChild('scrollbar5', { read: ScrollBarComponent, static: false }) scrollbar5: ScrollBarComponent;
    	@ViewChild('scrollbar6', { read: ScrollBarComponent, static: false }) scrollbar6: ScrollBarComponent;
    	@ViewChild('scrollbar7', { read: ScrollBarComponent, static: false }) scrollbar7: ScrollBarComponent;
    	@ViewChild('scrollbar8', { read: ScrollBarComponent, static: false }) scrollbar8: ScrollBarComponent;
    	@ViewChild('scrollbar9', { read: ScrollBarComponent, static: false }) scrollbar9: ScrollBarComponent;
    	@ViewChild('scrollbar10', { read: ScrollBarComponent, static: false }) scrollbar10: ScrollBarComponent;
    	@ViewChild('scrollbar11', { read: ScrollBarComponent, static: false }) scrollbar11: ScrollBarComponent;
    	@ViewChild('scrollbar12', { read: ScrollBarComponent, static: false }) scrollbar12: ScrollBarComponent;
    	@ViewChild('scrollbar13', { read: ScrollBarComponent, static: false }) scrollbar13: ScrollBarComponent;
    	
     
    	ngOnInit(): void {
    		// onInit code.
    	}
    
    	ngAfterViewInit(): void {
    		// afterViewInit code.
    		this.init();
        }
    		
    	init(): void {
    		// init code.
    	    
        
            const mediaSlider = document.getElementById('mediaSlider'), alarmSlider = document.getElementById('alarmSlider'), volumeSlider = document.getElementById('volumeSlider'), lowBatterySlider = document.getElementById('lowBatterySlider'), powerSaverSlider = document.getElementById('powerSaverSlider');
            function setIcon(event) {
                let below = "", above = "", off = "";
                const slider = event.target;
                switch (slider) {
                    case mediaSlider:
                        below = '<i class="material-icons">&#xE04D;</i>';
                        above = '<i class="material-icons">&#xE050;</i>';
                        off = '<i class="material-icons">&#xE04F;</i>';
                        break;
                    case alarmSlider:
                        below = above = '<i class="material-icons">&#xE855;</i>';
                        off = '<i class="material-icons">&#xE857;</i>';
                        break;
                    case volumeSlider:
                        below = '<i class="material-icons">&#xE7F5;</i>';
                        above = '<i class="material-icons">&#xE7F4;</i>';
                        off = '<i class="material-icons">&#xE7F6;</i>';
                        break;
                }
                if (slider.value === slider.min) {
                    slider.previousElementSibling.innerHTML = off;
                }
                else if (slider.value < slider.max / 2) {
                    slider.previousElementSibling.innerHTML = below;
                }
                else {
                    slider.previousElementSibling.innerHTML = above;
                }
            }
            function setBatteryLevel(event) {
                const slider = event.target;
                if (slider === lowBatterySlider) {
                    document.getElementById('lowBatteryAlert').textContent = slider.value.toString();
                }
                else {
                    document.getElementById('powerSaver').textContent = slider.value.toString();
                }
            }
            mediaSlider.addEventListener('change', setIcon);
            alarmSlider.addEventListener('change', setIcon);
            volumeSlider.addEventListener('change', setIcon);
            lowBatterySlider.addEventListener('change', setBatteryLevel);
            powerSaverSlider.addEventListener('change', setBatteryLevel);
        
    
    	}	
    }
    		

    app.module.ts

     
    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { ScrollBarModule } from 'smart-webcomponents-angular/scrollbar';
    
    import { AppComponent } from './app.component';
    
    @NgModule({
        declarations: [ AppComponent ],
        imports: [ BrowserModule, ScrollBarModule ],
        bootstrap: [ AppComponent ],
    	entryComponents: [ AppComponent ]
    })
    
    export class AppModule { }
    		


Running the Angular application

After completing the steps required to render a ScrollBar, run the following command to display the output in your web browser

ng serve
and open localhost:4200 in your favorite web browser.

Read more about using Smart UI for Angular: https://www.htmlelements.com/docs/angular-cli/.

Getting Started with React ScrollBar Component

Setup React Environment

The easiest way to start with React is to use create-react-app. To scaffold your project structure, follow the installation instructions.

	npm install -g create-react-app
	create-react-app my-app
	cd my-app
	npm start
	

Preparation

Open src/App.js andsrc/App.css

  1. Remove everything inside the App div tag in src/App.js:
    <div className="App"> </div>
  2. Remove the logo.svg import
  3. Remove the contents of src/App.css
  4. Remove src/logo.svg

Setup the ScrollBar

Smart UI for React is distributed as smart-webcomponents-react NPM package

  1. Download and install the package.
    npm install smart-webcomponents-react
  2. Once installed, import the React ScrollBar Component and CSS files in your application and render it app.js

    import 'smart-webcomponents-react/source/styles/smart.default.css';
    import React from "react";
    import ReactDOM from "react-dom";
    import { ScrollBar } from 'smart-webcomponents-react/scrollbar';
    
    class App extends React.Component {
    
    	init() {
    
    
    		const mediaSlider = document.getElementById('mediaSlider'),
    			alarmSlider = document.getElementById('alarmSlider'),
    			volumeSlider = document.getElementById('volumeSlider'),
    			lowBatterySlider = document.getElementById('lowBatterySlider'),
    			powerSaverSlider = document.getElementById('powerSaverSlider');
    
    		function setIcon(event) {
    			let below = "",
    				above = "",
    				off = "";
    			const slider = event.target;
    			switch (slider) {
    				case mediaSlider:
    					below = '<i class="material-icons">&#xE04D;</i>';
    					above = '<i class="material-icons">&#xE050;</i>';
    					off = '<i class="material-icons">&#xE04F;</i>';
    					break;
    				case alarmSlider:
    					below = above = '<i class="material-icons">&#xE855;</i>';
    					off = '<i class="material-icons">&#xE857;</i>';
    					break;
    				case volumeSlider:
    					below = '<i class="material-icons">&#xE7F5;</i>';
    					above = '<i class="material-icons">&#xE7F4;</i>';
    					off = '<i class="material-icons">&#xE7F6;</i>';
    					break;
    			}
    			if (slider.value === slider.min) {
    				slider.previousElementSibling.innerHTML = off;
    			} else if (slider.value < slider.max / 2) {
    				slider.previousElementSibling.innerHTML = below;
    			} else {
    				slider.previousElementSibling.innerHTML = above;
    			}
    		}
    
    		function setBatteryLevel(event) {
    			const slider = event.target;
    			if (slider === lowBatterySlider) {
    				document.getElementById('lowBatteryAlert').textContent = slider.value.toString();
    			} else {
    				document.getElementById('powerSaver').textContent = slider.value.toString();
    			}
    		}
    		mediaSlider.addEventListener('change', setIcon);
    		alarmSlider.addEventListener('change', setIcon);
    		volumeSlider.addEventListener('change', setIcon);
    		lowBatterySlider.addEventListener('change', setBatteryLevel);
    		powerSaverSlider.addEventListener('change', setBatteryLevel);
    
    	}
    
    
    	componentDidMount() {
    
    	}
    
    	render() {
    		return (
    			<div>
    				<section>
    					<div>
    						<h2>Scrollbars let users to select values by moving the scrollbar thumb.</h2>
    						<div class="module">
    							<p>Scrollbars are ideal components for adjusting settings that reflect intensity
    			                    levels, such as volume, brightness, or color saturation.</p>
    						</div>
    					</div>
    				</section>
    				<section id="continuousSliders">
    					<h2>Continuous scrollbar</h2>
    					<div class="module">
    						<p>Use continuous scrollbars for subjective settings that do not require
    			                a specific value for the user to make meaningful adjustments.</p>
    					</div>
    					<div class="module continuousSliderLight">
    						<table>
    							<tr>
    								<td>
    									<p>Normal</p>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar ></ScrollBar>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar  max={100} value={50}></ScrollBar>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar  max={100} value={100}></ScrollBar>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<p>Disabled</p>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar  disabled max={100}></ScrollBar>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar  disabled max={100} value={50}></ScrollBar>
    								</td>
    							</tr>
    							<tr>
    								<td>
    									<ScrollBar  disabled max={100} value={100}></ScrollBar>
    								</td>
    							</tr>
    						</table>
    					</div>
    				</section>
    				<section id="verticalSliders">
    					<h2>Orientation</h2>
    					<div class="module">
    						<p>smartScrollBar can be horizontal or vertical depending on the orientation
    			                property.</p>
    					</div>
    					<div class="module">
    						<div>
    							<ScrollBar  max={100} value={50}></ScrollBar>
    							<br />
    							<br />
    							<ScrollBar  orientation="vertical" max={100} value={75}></ScrollBar>
    						</div>
    						<br />
    						<p>Vertical scrollbars</p>
    					</div>
    				</section>
    				<section id="demoSliders">
    					<h2>Demo</h2>
    					<div class="module">
    						<p>ScrollBars are controls that are used for adjusting values precisely.</p>
    					</div>
    					<div class="module media-controls">
    						<div>
    							<h2>Volumes</h2>
    							<div>
    								<h3>Media volume</h3>
    								<div id="mediaControl" class="controls"> <i class="material-icons">&#xE04D;</i>
    									<ScrollBar  id="mediaSlider"
    										max={100} value={25}></ScrollBar>
    								</div>
    							</div>
    							<div>
    								<h3>Alarm volume</h3>
    								<div id="alarmControl" class="controls"> <i class="material-icons">&#xE855;</i>
    									<ScrollBar  id="alarmSlider"
    										max={100} value={50}></ScrollBar>
    								</div>
    							</div>
    							<div>
    								<h3>Ring volume</h3>
    								<div id="ringControl" class="controls"> <i class="material-icons">&#xE7F4;</i>
    									<ScrollBar  id="volumeSlider"
    										max={100} value={75}></ScrollBar>
    								</div>
    							</div>
    						</div>
    					</div>
    					<div class="module power-controls">
    						<div>
    							<h2>Battery Saver Mode</h2>
    							<div>
    								<h3>Low battery alert on <b id="lowBatteryAlert">15</b> %</h3>
    								<div id="mediaControl" class="controls"> <i class="material-icons">&#xE8B2;</i>
    									<ScrollBar  id="lowBatterySlider"
    										max={100} value={15} scaleType="integer"></ScrollBar>
    								</div>
    							</div>
    							<div>
    								<h3>Power saver mode active on <b id="powerSaver">50</b>%</h3>
    								<div id="alarmControl" class="controls"> <i class="material-icons">&#xE19C;</i>
    									<ScrollBar  id="powerSaverSlider"
    										max={100} value={50} scaleType="integer"></ScrollBar>
    								</div>
    							</div>
    						</div>
    					</div>
    				</section>
    			</div>
    		);
    	}
    }
    
    ReactDOM.render(<App />, document.querySelector("#root"));
    
    export default App;
    	

Running the React application

Start the app with
npm start
and open localhost:3000 in your favorite web browser to see the output.

Read more about using Smart UI for React: https://www.htmlelements.com/docs/react/.

Getting Started with Vue ScrollBar Component


Setup Vue Environment

We will use vue-cli to get started. Let's install vue-cli

npm install -g @vue/cli

Then we can start creating our Vue.js projects with:

vue create my-project

Setup the ScrollBar

Open the "my-project" folder and run:

npm install smart-webcomponents

Setup with Vue 3.x

  • Make Vue ignore custom elements defined outside of Vue (e.g., using the Web Components APIs). Otherwise, it will throw a warning about an Unknown custom element, assuming that you forgot to register a global component or misspelled a component name.

    Open src/main.js in your favorite text editor and change its contents to the following:

    main.js

    import { createApp } from 'vue'
    import App from './App.vue'
    
    const app = createApp(App)
    
    app.config.isCustomElement = tag => tag.startsWith('smart-');
    app.mount('#app')
    		
  • Open src/App.vue in your favorite text editor and change its contents to the following:

    App.vue

    <template>
      <div class="vue-root">
        <smart-scroll-bar id="test" style></smart-scroll-bar>
      </div>
    </template>
    
    <script>
    import { onMounted } from "vue";
    import "smart-webcomponents/source/styles/smart.default.css";
    import "smart-webcomponents/source/modules/smart.scrollbar.js";
    
    export default {
      name: "app",
      setup() {
        onMounted(() => {
          const mediaSlider = document.getElementById("mediaSlider"),
            alarmSlider = document.getElementById("alarmSlider"),
            volumeSlider = document.getElementById("volumeSlider"),
            lowBatterySlider = document.getElementById("lowBatterySlider"),
            powerSaverSlider = document.getElementById("powerSaverSlider");
    
          function setIcon(event) {
            let below = "",
              above = "",
              off = "";
            const slider = event.target;
            switch (slider) {
              case mediaSlider:
                below = '<i class="material-icons">&#xE04D;</i>';
                above = '<i class="material-icons">&#xE050;</i>';
                off = '<i class="material-icons">&#xE04F;</i>';
                break;
              case alarmSlider:
                below = above = '<i class="material-icons">&#xE855;</i>';
                off = '<i class="material-icons">&#xE857;</i>';
                break;
              case volumeSlider:
                below = '<i class="material-icons">&#xE7F5;</i>';
                above = '<i class="material-icons">&#xE7F4;</i>';
                off = '<i class="material-icons">&#xE7F6;</i>';
                break;
            }
            if (slider.value === slider.min) {
              slider.previousElementSibling.innerHTML = off;
            } else if (slider.value < slider.max / 2) {
              slider.previousElementSibling.innerHTML = below;
            } else {
              slider.previousElementSibling.innerHTML = above;
            }
          }
    
          function setBatteryLevel(event) {
            const slider = event.target;
            if (slider === lowBatterySlider) {
              document.getElementById(
                "lowBatteryAlert"
              ).textContent = slider.value.toString();
            } else {
              document.getElementById(
                "powerSaver"
              ).textContent = slider.value.toString();
            }
          }
          mediaSlider.addEventListener("change", setIcon);
          alarmSlider.addEventListener("change", setIcon);
          volumeSlider.addEventListener("change", setIcon);
          lowBatterySlider.addEventListener("change", setBatteryLevel);
          powerSaverSlider.addEventListener("change", setBatteryLevel);
        });
      }
    };
    </script>
    
    <style>
    /* fallback */
    @font-face {
      font-family: "Material Icons";
      font-style: normal;
      font-weight: 400;
      src: url(https://fonts.gstatic.com/s/materialicons/v31/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2)
        format("woff2");
    }
    
    .material-icons {
      font-family: "Material Icons";
      font-weight: normal;
      font-style: normal;
      font-size: inherit;
      line-height: 1;
      letter-spacing: normal;
      text-transform: none;
      display: inline-block;
      white-space: nowrap;
      word-wrap: normal;
      direction: ltr;
      -webkit-font-feature-settings: "liga";
      -webkit-font-smoothing: antialiased;
    }
    
    smart-scroll-bar {
      width: 250px;
      height: 17px;
    }
    smart-scroll-bar[orientation="vertical"] {
      width: 17px;
      height: 250px;
    }
    </style>
    		
    We can now use the smart-scroll-bar with Vue 3. Data binding and event handlers will just work right out of the box.

Setup with Vue 2.x

  • Make Vue ignore custom elements defined outside of Vue (e.g., using the Web Components APIs). Otherwise, it will throw a warning about an Unknown custom element, assuming that you forgot to register a global component or misspelled a component name.

    Open src/main.js in your favorite text editor and change its contents to the following:

    main.js

    import Vue from 'vue'
    import App from './App.vue'
    
    Vue.config.productionTip = false
    Vue.config.ignoredElements = [
    'smart-scroll-bar'
    ]
    
    new Vue({
      render: h => h(App),
    }).$mount('#app')
  • Open src/App.vue in your favorite text editor and change its contents to the following:

    App.vue

    <template>
      <div class="smart-demo-container">
        <smart-scroll-bar  max="100" value="50"></smart-scroll-bar>
        <br>
        <smart-scroll-bar  orientation="vertical" max="100" value="50"></smart-scroll-bar>
      </div>
    </template> 
    
    <script>
    import "smart-webcomponents/source/smart.elements.js";
    import "smart-webcomponents/source/styles/smart.default.css";
    
    export default {
      name: "app"
    };
    </script>
    
    <style>
      .smart-demo-container {
        margin: 0 !important;
      }
    
      smart-scroll-bar {
        width: 250px;
        height: 22px;
      }
      
      smart-scroll-bar[orientation="vertical"] {
        width: 22px;
        height: 250px;
      }
    </style>
    		
    We can now use the smart-scroll-bar with Vue. Data binding and event handlers will just work right out of the box.
    We have bound the properties of the smart-scroll-bar to values in our Vue component.

Running the Vue application

Start the app with
npm run serve
and open localhost:8080 in your favorite web browser to see the output below:

Read more about using Smart UI for Vue: https://www.htmlelements.com/docs/vue/.