PlayBox is a JavaScript library created by Deepak Kumar, This library helps to displays HTML, image slider by filling the screen and dimming out the web page.
This PlayBox Library does not use any other external Library, It also contains some of the polyfill jQuery functions.
Download the Latest version of PlayBox from the GitHub release page
Download from: PlayBox GitHub Release
Include the playbox.js into your document, this PlayBox library injects necessary stylesheet into the document header when the page loads. you can override those values in custom css by !important property.
<script src='playbox.js'></script>
Create a div tag in the body section mentioned below, and you can use any number of boxes as with unique different containerName and buttonName, below are the examples of playbox use cases
Note: The cssSelector mentioned in below examples also support PlayBox.getElement() and Javascript document selected Object
<div class="playbox containerName">
<div class="container">
...
...
...
</div>
</div>
<button class="buttonName">Click Me</button>
<script type="text/javascript">
PlayBox.open('.buttonName', '.containerName', 200, 300);
</script>
Note: 200, 300 are fadein and fadeout duration in milliseconds for box and it’s optional, the default duration is 300 milliseconds
<div class="playboximage containerName">
...
... <!-- If you like your other elements here -->
...
</div>
<button class="buttonName">Click Me</button>
<script type="text/javascript">
PlayBox.imageOpen('.buttonName', '.containerName', ['image1.jpg','image2.jpg',...], 200, 300);
</script>
Note: 200, 300 are fadein and fadeout duration in milliseconds for box and it’s optional, the default duration is 300 milliseconds
<div class="cssSelector">Sample Element</div>
<script type="text/javascript">
PlayBox.fadeIn('.cssSelector', 300, function(){});
</script>
Note 1: 300 are fadein duration in milliseconds for the element and it’s optional, the default delay is 100 milliseconds
Note 2: The third argument is a callback function after the fadein animation is complete the callback function executed, and it’s an optional argument
<div class="cssSelector">Sample Element</div>
<script type="text/javascript">
PlayBox.fadeOut('.cssSelector', 300, function(){});
</script>
Note 1: 300 are fadeout duration in milliseconds for the element and it’s optional, the default delay is 100 milliseconds, after the animation is completed the element display property set to display:none
Note 2: The third argument is a callback function after the fadeout animation is complete the callback function executed, and it’s an optional argument
We can also nest the callback function on each other
PlayBox.fadeOut('.cssSelector', 1000, function(){
PlayBox.fadeIn('.cssSelector', 1000, function(){
alert("Animation Completed")
});
});
This Selector will return an HTMLElement of the selected DOM element,
PlayBox.getElement('cssSelector');
Note 1: This function will return the first occurrence of the element in the DOM
This Selector will return an array of Elements, of the selected DOM element, You can perform all Array operations on those elements,
PlayBox.getElements('cssSelector');
This Selector will return all the first level child element as NodeList,
PlayBox.children('cssSelector');
Note 1: If you like to do Array operations on those NodeList, pass the NodeList into PlayBox.getElements(NodeList) this will return a Array of Children
This method inserts specified HTML content to the end of the selected elements,
PlayBox.append('cssSelector', '<tag>Element</tag>');
This method inserts specified HTML content to the beginning of the selected elements,
PlayBox.prepend('cssSelector', '<tag>Element</tag>');
This method return true if the have the specifed class else it will return false,
PlayBox.hasClass('cssSelector', 'className');
This method return true if the selected element is a specifed tag name element, else it will return false.
PlayBox.is('cssSelector', 'HTMLTagName');
This method return index integer of the element relative to it’s parent Element .
PlayBox.index('cssSelector');
This method add the click event handler to the selected element and execute the callback function if the element was clicked.
PlayBox.click('cssSelector', function(){
alert('Element Clicked');
});
Author: deepakplay
Source Code: https://github.com/deepakplay/playbox-js
#javascript