Skip to content

Commit

Permalink
Removed unnecessary requestAnimationFrame (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
electerious committed Feb 23, 2018
1 parent e82ed10 commit ab2a2df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.0.1] - 2018-02-23

### Changed

- Removed unnecessary `requestAnimationFrame` (#12)

## [4.0.0] - 2017-12-22

### New
Expand Down
2 changes: 1 addition & 1 deletion dist/basicLightbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,14 @@ const render = function(html = '', opts) {
*/
const show = function(elem, next) {

// Append lightbox to DOM
document.body.appendChild(elem)

// Wait a while to ensure that the class change triggers the animation
setTimeout(() => {
requestAnimationFrame(() => {

// Show lightbox
elem.classList.add('basicLightbox--visible')

// Continue with the callback
return next()

})
Expand All @@ -143,22 +140,17 @@ const show = function(elem, next) {
*/
const close = function(elem, next) {

// Hide lightbox
elem.classList.remove('basicLightbox--visible')

setTimeout(() => {
requestAnimationFrame(() => {

// Don't continue to remove lightbox when element missing
if (visible(elem)===false) return next()
// Don't continue to remove lightbox when element missing
if (visible(elem)===false) return next()

// Remove lightbox from DOM
elem.parentElement.removeChild(elem)
elem.parentElement.removeChild(elem)

// Continue with the callback
return next()
return next()

})
}, 410)

return true
Expand Down

0 comments on commit ab2a2df

Please sign in to comment.