- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
var Scroller = function (scroll_left,scroll_right,visible_part,scroll_part) {
this.scroll_right = jQuery(scroll_left); //scroll to left
this.scroll_left = jQuery(scroll_right); //scroll to right
this.slider = jQuery(scroll_part); //scroll element
this.visible_part = jQuery(visible_part);
this.width_slider_elements = this.slider.width();
this.width_slider_element = this.slider.find('li:eq(0)').width();
this.width_visible_part = this.visible_part.width();
this.temp_process = true;
if(this.width_slider_elements < this.width_visible_part) {temp_process = false;}
var self = this;
this.scroll_left.click(function()
{
if (self.temp_process) {
self.temp_process = false;
self.slide(true);
}
return false;
});
this.scroll_right.click(function()
{
if (self.temp_process) {
self.temp_process = false;
self.slide(false);
}
return false;
});
return this;
};
Scroller.prototype.slide = function (side) {
var self = this;
var shift = (self.width_visible_part - self.width_slider_element)/2;
var current_shift = Math.abs(self.slider.css('left').replace('px',''));
if (side) { //left
shift = (current_shift+shift+self.width_visible_part) > self.width_slider_elements ? self.width_slider_elements - current_shift - self.width_visible_part : shift;
self.slider.animate({left: '-='+shift+'px'}, 1000, function(){ self.temp_process = true;});
} else { //right
shift = shift > current_shift ? current_shift : shift;
self.slider.animate({left: '+='+shift+'px'}, 1000, function(){ self.temp_process = true;});
}
return shift;
};
guest 01.03.2010 23:42 # 0
guest 02.03.2010 08:30 # +1
guest 02.03.2010 12:28 # +4
Еще и баги могли найти, пока домой ехал :)
guest 11.04.2015 22:49 # 0