Usage

Ad-rotator.js usage guide in detail. There are 3 basic steps to be followed as explained below...


1. HTML

Add any container element like a div, aside, etc... to your HTML. This is where ad-units will be injected.

HTML
<div id="containerElement"></div>

2. Import the library 📦️

Import the javascript and the CSS into your project/app.


3. Initialize & configure ⚙️

Initialize Ad-rotator.js by passing to it the required configuration parameters

Ad sizes are completely controlled via CSS. Feel free to use media queries to tweak the dimensions. See common sizes for responsive Ads to use ad dimensions that suit your needs.


✨ Demo ✨

Here is a live demo in action. Feel free to tinker with it to see the results in real-time.

<!-- Include assets -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ad-rotator/dist/style.css" />
<script src="https://cdn.jsdelivr.net/npm/ad-rotator"></script>

<!-- container element -->
<div id="containerElement"></div>
<hr>
Ad-rotator.js
#containerElement { /* set Ad size */
  height: 250px;
  width: 250px;
  margin: auto; /* optional */
}
img {
  /* set img elements to be responsive */
  height: 100%;
  width: 100%;
  /* Stretch img to fit container [optional] */
  object-fit: cover;
}

/* styling to ignore */
body {
  text-align: center;
}
// initialize ad-rotator
const instance = rotator(
  document.getElementById('containerElement'),
  getAds()
);

// start the rotation
instance.start();

// ads
function getAds() {
  return [
    { url: 'https://fusionplatter.eu#1', img: 'https://niketpathak.com/images/works/gkm_pic_sq.jpg'},
    { url: 'https://digitalfortress.tech#2', img: 'https://niketpathak.com/images/works/maestrobits_sq.jpg'},
    { url: 'https://gospelmusic.io#3', img: 'https://niketpathak.com/images/works/halcyonminds_sq.jpg'}
  ];
}

More advanced examples can be found on the Playground.


Next
Config
Previous
Install