Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. var Gallery = function Gallery(params){
  2. this.id = params.id;
  3. this.scrollTime = params.scrollTime;
  4.  
  5. this.container = jq_144('#' + this.id + ' .gallery-container');
  6. this.prevNode = jq_144('#' + this.id + ' .gallery-prev');
  7. this.nextNode = jq_144('#' + this.id + ' .gallery-next');
  8.  
  9. this.init();
  10. };
  11.  
  12. Gallery.prototype.move = function(number){
  13. number = number || 0;
  14. var states = this.states;
  15. var state = this.container.css('left');
  16. var pos = states.indexOf(state) + number;
  17. if(pos == -1){
  18. pos = states.length - 1;
  19. } else if(pos == states.length){
  20. pos = 0;
  21. }
  22. this.container.animate({
  23. 'left' : states[pos]},
  24. 500
  25. );
  26. };
  27.  
  28. Gallery.prototype.init = function(){
  29. var container = this.container;
  30.  
  31. var w = container.width();
  32. var h = container.parent().height();
  33. var childs = container.find('> a');
  34.  
  35. var margT = 0;
  36. if(childs.length > 1){
  37. margT = childs.eq(1).outerWidth(true) - childs.eq(1).outerWidth();
  38. }
  39. var w2 = margT + childs.eq(0).width();
  40.  
  41. var clen = 6;
  42.  
  43. container
  44. .css('height', h + 'px')
  45. .css('width', w * (clen + 1) + 'px')
  46. .css('left', '0px');
  47.  
  48. var states = this.states = [];
  49. for(var i =0; i < clen;i++){
  50. states.push(-i*(w2) + 'px');
  51. }
  52.  
  53. var that = this;
  54. this.prevNode.click(function(e){
  55. e.preventDefault();
  56. that.move(-1);
  57. });
  58. this.nextNode.click(function(e){
  59. e.preventDefault();
  60. that.move(1);
  61. });
  62. if(this.scrollTime){
  63. setInterval(function(){
  64. that.move(1);
  65. }, this.scrollTime * 1000);
  66. }
  67. childs.filter('[href]').fancybox({
  68. 'transitionIn' : 'none',
  69. 'transitionOut' : 'none',
  70. 'titlePosition' : 'over',
  71. 'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
  72. return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
  73. }
  74. });
  75.  
  76. };
  77.  
  78. widget.init('gallery', Gallery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement