ngx-image-comparison-slider
Image comparison component with slider, for Angular.
See an example here.
Works on mobile too!
Table of contents
Installing
- Run
npm install ngx-image-comparison-slider
to install library. - Import
NgxImageComparisonSliderModule
to yourAppModule
(or any module of choice).
import {NgxImageComparisonSliderModule} from 'ngx-image-comparison-slider';
@NgModule({
imports: [ NgxImageComparisonSliderModule ],
...
})
export class AppModule { }
Usage
Simply use <ngx-image-comparison-slider>
component anywhere in your template.
<h1>Example</h1>
<ngx-image-comparison-slider
src1='https://www.w3schools.com/html/pic_trulli.jpg'
src2='https://www.w3schools.com/html/img_girl.jpg'>
</ngx-image-comparison-slider>
See more examples here
Additional options
Option | Type | Default | Explanation |
---|---|---|---|
src1 |
string | null | Source of the first (left-side) image |
src2 |
string | null | Source of the second (right-side) image |
startPos |
'leftBorder' 'middle' 'rightBorder' number |
'middle' |
Starting position for slider: Left, Centered, Right, or a number (measured from left, in px) |
maxWidth |
number | 600 | Maximum Width of the component in px |
maxHeight |
number | 400 | Maximum Height of the component in px |
imageFit |
'cover' 'contain' 'fill'
|
'cover' |
Fit mode for images (using objectFit css property) |
leftBorder |
number | 0 | Left maximum for sliding (in px) |
rightBorder |
number | same as maxWidth
|
Right maximum for sliding (measured from left, in px) |
alt1 |
string | 'sliderImage1' |
Alt (name) of the first (left-side) image |
alt2 |
string | 'sliderImage2' |
Alt (name) of the second (right-side) image |
sliderWidth |
number | 5 |
Width of the slider line (in px) |
sliderColor |
string (css collor) | 'whitesmoke' |
Color of the slider line |
sliderShadow |
bool | true |
Shows or hides a slight shadow on the slider |
sliderBallSize |
number |
sliderWidth * 4 |
Radius of circle in the middle of slider line |
sliderBallImageColor |
'black' 'white'
|
'black' |
Color of the icon image, inside of slider ball |
showSliderBall |
bool | true |
Show or hide slider ball |
calcSliderBallDif |
bool | true |
Take slider ball into consideration when calculating right and left borders for sliding |
zIndexStart |
number | 1000 | Defines the base for z-index property of images and slider |
Examples
Go ahead and experiment yourself on stackblitz!
Licence
The MIT License (MIT)
Copyright (c) 2021 Web-Ez LTD.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.