thumbnails.js 952 B

1234567891011121314151617181920212223242526272829303132
  1. class Thumbnails {
  2. constructor (container, width, url, events) {
  3. this.container = container;
  4. this.width = width;
  5. this.container.style.backgroundImage = `url('${url}')`;
  6. this.events = events;
  7. }
  8. resize (width, height) {
  9. this.container.style.width = `${width}px`;
  10. this.container.style.height = `${height}px`;
  11. this.container.style.top = `${-height + 2}px`;
  12. }
  13. show () {
  14. this.container.style.display = 'block';
  15. this.events && this.events.trigger('thumbnails_show');
  16. }
  17. move (position) {
  18. this.container.style.backgroundPosition = `-${(Math.ceil(position / this.width * 100) - 1) * 160}px 0`;
  19. this.container.style.left = `${(position - this.container.offsetWidth / 2)}px`;
  20. }
  21. hide () {
  22. this.container.style.display = 'none';
  23. this.events && this.events.trigger('thumbnails_hide');
  24. }
  25. }
  26. module.exports = Thumbnails;