ATTENTION: This version of component is outdated and not supported anymore. We strongly recommend to use Flex Gallery component, which is more flexible alternative.
If you are more familiar with banners you can jump straight to quick-docs.
var Slider = Adf.Slider;
Slider.init(options);
// append component to our banner
document.getElementById('bannerWrap').appendChild(Slider.containerElement);
Slider.slideLeft()
Slider.slideRight()
Read more at Actions.
Slider.on(Slider.EVENTS.TRANSITION_START, function(metaData){
// Do something
})
Read more at Events.
This component has a lot of default options, however they can be modified. They are provided as an object during Slider.init(options)
. You can jump straight to examples to see full configurations.
By default component rotation is horizontal, but you can change it to vertical by specifying it in options.
var options = {
isVertical: true
}
To configure slide animation add animation
object to options.
var options = {
animation: {
scaleAtTheStart: 1,
transitionDuration: 1.5,
scaleAtTheEnd: 1,
panelDistance: 1,
easing: 'linear'
}
}
To include auto-rotation in the component add autoRotator
variable to options.
var options = {
animation: {
...
},
autoRotator: {
plan: Slider.ACTIONS.SLIDE_RIGHT,
timeout: true
}
}
It automatically pauses for 10 seconds on any user interaction, for example if every 9 seconds user move over or clicks banner, it will always be paused.
It automatically stop auto-rotation after 25 seconds. To turn it off, set timeout to false.
autoRotator: {
plan: [[<banner action>, <times>, <delay>], <delay>, [<banner action>, <times>, <delay>], ...],
startDelay: 1.5,
pauseTime: 10,
timeoutTime: 25
}
Panels are proved as an array in options, where each value in array is considered a panel. Minimum number of panels is 2, maximum unlimited.
There are few different way you can define a panel:
1) Simply by providing an image url from additional assets with html.getAsset(n), in this case an <img/>
elements will be created with global clickTAGs.
var options = {
animation: {
...
},
autoRotator: {
...
},
panels: [
dhtml.getAsset(1),
dhtml.getAsset(2),
dhtml.getAsset(3),
]
}
2) By providing an object with element and clickTAG properties, in this case a provided clickTAG will be used for panel. If clickTAG propery is not defined, then panel will have no clickTAG.
panels: [{
element: ANY_DOM_ELEMENT_1,
clickTAG: 'https://www.adform.com'
}, {
element: ANY_DOM_ELEMENT_2,
clickTAG: 'https://www.adform.com'
}, {
element: ANY_DOM_ELEMENT_3,
clickTAG: 'https://www.adform.com'
},
]
You can also define callbacks to be invoked when panel slides into center (onShow
) and when slides out (onHide
).
panels: [
...
{
element: ANY_DOM_ELEMENT_1,
clickTAG: 'https://www.adform.com',
onShow: function() {},
onHide: function() {}
}
...
]
Adf.Slider
has these actions (methods):
isVertical
must be set to true).isVertical
must be set to true).All available actions are defined at Adf.Slider.ACTIONS and can be invoked directly on component Adf.Slider.slideLeft
or passed on as Adf.Slider.ACTIONS.SLIDE_LEFT
to auto-rotator to be invoked later .
To subscribe to events call Adf.Slider.on(EVENT_NAME, callback)
method.
Event constants can be found at: Adf.Slider.EVENTS {object}
.
EVENT | ARGUMENTS | COMMENTS |
---|---|---|
TRANSITION_START | {direction: string} | fires before transition animation starts |
TRANSITION_END | {direction: string} | fires after animation ends |
EVENT | ARGUMENTS | COMMENTS |
---|---|---|
WHEEL_UP | - | |
WHEEL_DOWN | - | |
SWIPE_LEFT | event | |
SWIPE_RIGHT | event | |
SWIPE_UP | event | |
SWIPE_DOWN | event | |
MOUSEOVER | event | |
MOUSEOUT | event | |
CLICK | event |
Simple #1
Studio
var Slider = Adf.Slider;
/* Initialize banner */
Slider.init({
panels: [
dhtml.getAsset(1),
dhtml.getAsset(2),
dhtml.getAsset(3),
dhtml.getAsset(4),
]
});
Simple #2
Studio
var Slider = Adf.Slider;
/* Initialize banner */
Slider.init({
animation: {
scaleAtTheStart: 1,
transitionDuration: 0.7,
scaleAtTheEnd: 0.5,
panelDistance: 0.7
},
autoRotator: {
plan: Slider.ACTIONS.SLIDE_RIGHT
},
panels: [
dhtml.getAsset(1),
dhtml.getAsset(2),
dhtml.getAsset(3),
dhtml.getAsset(4),
]
});
Advanced #1
Studio
function createImgElement(src) {
var element = document.createElement('img');
element.src = src;
return element
}
Slider.init({
animation: {
scaleAtTheStart: 1,
transitionDuration: 0.7,
scaleAtTheEnd: 0.5,
panelDistance: 0.7
},
autoRotator: {
plan: [
[Slider.ACTIONS.SLIDE_RIGHT, 5, 1], 2, [Slider.ACTIONS.SLIDE_LEFT, 10, 3]
] // slide right 5 times every 1 sec, 2 sec pause, slide left 10 times every 3 sec
},
panels: [{
element: createImgElement(dhtml.getAsset(1)),
clickTAG: 'http://www.example.com'
}, {
element: createImgElement(dhtml.getAsset(2)),
clickTAG: 'http://www.adform.com'
}, {
element: createImgElement(dhtml.getAsset(3)),
clickTAG: 'http://www.google.com'
}, {
element: createImgElement(dhtml.getAsset(4))
}]
});
Advanced #2
Studio
function createImgElement(src) {
var element = document.createElement('img');
element.src = src;
return element
}
var Slider = Adf.Slider;
/* Initialize banner */
Slider.init({
animation: {
scaleAtTheStart: 1,
transitionDuration: 0.5,
scaleAtTheEnd: 1,
panelDistance: 1
},
autoRotator: {
startDelay: 3,
plan: [
[Slider.ACTIONS.SLIDE_RIGHT, 5, 1], 2, [Slider.ACTIONS.SLIDE_LEFT, 10, 3]
]
},
panels: [{
element: createImgElement(dhtml.getAsset(1)),
clickTAG: 'http://www.example.com',
onShow: function() {
console.log('SHOW Panel 1!')
},
onHide: function() {
console.log('HIDE Panel 1!')
}
}, {
element: createImgElement(dhtml.getAsset(2)),
onShow: function() {
console.log('SHOW Panel 2!')
},
onHide: function() {
console.log('HIDE Panel 2!')
}
}]
});
var Slider = Adf.Slider;
/* Initialize banner */
Slider.init({
isVertical: false,
animation: { /* optional */
scaleAtTheStart: 1, // transform: scale() when banner is in center
transitionDuration: 0.5, // in seconds
scaleAtTheEnd: 1, // transform: scale() when banner is out of center
panelDistance: 1, // 1 - panels are next to each other, 0 - they overlap
easing: 'linear' // linear, easeInQuad, easeOutQuad, easeInOutQuad
},
autoRotator: { /* optional */
startDelay: 3, // in seconds
plan: [
[Slider.ACTIONS.SLIDE_RIGHT, 100, 1], 2, [Slider.ACTIONS.SLIDE_LEFT, 10, 3]
] // [[direction, times, delay], delay, [...]]
},
panels: [{ /* required */
element: createImgElement(dhtml.getAsset(1)),
clickTAG: 'http://www.example.com',
onShow: function() {
console.log('SHOW Panel 1!')
},
onHide: function() {
console.log('HIDE Panel 1!')
}
}, {
element: createImgElement(dhtml.getAsset(2)),
onShow: function() {
console.log('SHOW Panel 2!')
},
onHide: function() {
console.log('HIDE Panel 2!')
}
}]
});