0
A
回答
0
可以SEEE頁面上的滑塊的源代碼。我希望你能弄清楚滑塊是如何設置的。
$(document).ready(function() {
//'magic' numbers
var width_tab = 65;
var width_active = 835;
var duration_grow = 1000;
var slider_duration = 5000;
//scope globals
var currentPanel = 0;
var panels = null;
var control_area = $('#jdi_slider_control');
var controls = null;
//setup the panels
var setupPanels = function(index) {
panels = $('#jdi_slider').children();
//setup the panel (no controls)
for(var i = 0; i < panels.length; i++) {
switch (i) {
case index : $(panels[i]).css({'z-index':3,'left':width_active}); break;
case currentPanel : $(panels[i]).css({'z-index':2}); break;
default : $(panels[i]).css({'z-index':1})
}
}
//after all the setup, then force map
$('#jdi_slider_container').css({'background-color':$(panels[index]).css('background-color')});
$('#jdi_slider_background').css({'width':0,'right':0,'background-color':$(panels[index]).css('background-color')});
$(panels[index]).css({'left':0});
}
var setupControls = function(index) {
//setup the controls
//we know the number of panels, so compute
for (var i = 0; i < panels.length; i++) {
var img_element = $(panels[i]).find('img').eq(0).clone();
img_element.attr('href',null);
$('#jdi_slider_control').append(img_element);
}
$('#jdi_slider_control img').wrap("<div class='jdi_slider_control_panel'></div>");
control_area = $('#jdi_slider_control');
controls = control_area.children();
control_area.css({'width':(controls.length - 1)*width_tab+'px'});
}
var activatePanel = function(index) {
//animate the changes
//set the new panel to the desired area
//do the set up of the new panel
for(var i = 0; i < panels.length; i++) {
switch (i) {
case index : $(panels[i]).css({'z-index':3,'left':width_active}); break;
case currentPanel : $(panels[i]).css({'z-index':2}); break;
default : $(panels[i]).css({'z-index':1})
}
}
//setup the color
$('#jdi_slider_container').css({'background-color':$(panels[currentPanel]).css('background-color')});
//do the animations
//first, setup initial conditions
$('#jdi_slider_background').css({'width':$('#jdi_slider_control').width(),'right':0,'background-color':$(panels[index]).css('background-color')});
//animate the slider to 100% width (from initial width)
$('#jdi_slider_background').animate({'width':'100%' },{duration:duration_grow ,queue:false,
progress: function() {
//progress function to sync to moving of the img
//find if the current width is within the area of our interest
var slider = $('#jdi_slider');
var leftEdge = slider.offset().left;
var rightEdge = leftEdge + slider.width();
var jdi_background = $('#jdi_slider_background');
var position = jdi_background.offset().left;
if ((position >= leftEdge) & (position <= rightEdge)) {
$(panels[index]).css({'left':position - leftEdge + 'px'});
}
//in case the step 'hops' the exact left edge (which it will)
if (position < leftEdge) {
$(panels[index]).css({'left':0});
}
},
complete: function() {
//paranoia, after complete, then ensure leftness
$(panels[index]).css({'left':0});
}
});
//now aanimate the control
var offsets = new Array(panels.length);
for (var i = 0; i < panels.length; i++) {
offsets[i] = (i + index) % panels.length;
}
$(controls[offsets[panels.length-1]]).css({'right':'-'+width_tab+'px'});
var sum_right = 0;
$(controls[offsets[0]]).animate({'right':control_area.width()},{duration:duration_grow,queue:false,complete:function() {$(this).css({'right':'-'+width_tab+'px'})} });
for(var i = offsets.length - 1; i > 0; i--) {
$(controls[offsets[i]]).animate({'right':sum_right},{duration:duration_grow,queue:false});
sum_right += width_tab;
}
//finally, update the currentPanel
currentPanel = index;
}
//on timer fire, advance the thingy
var advanceSlider = function() {
//alter the i to the required setting
panelToActivate = (currentPanel + 1) % panels.length;
activatePanel(panelToActivate);
};
if (typeof jdi_slider_timer !== 'undefined') {
clearInterval(jdi_slider_timer);
}
jdi_slider_timer = setInterval(advanceSlider,slider_duration);
//add mouse events
$('#jdi_slider_container').hover(function(ev){
clearInterval(jdi_slider_timer);
jdi_slider_timer = null;
}, function(ev){
jdi_slider_timer = setInterval(advanceSlider, slider_duration);
});
setupPanels(0);
setupControls();
activatePanel(0);
//attach a click event to the slider
$('div.jdi_slider_control_panel').click(function() {
//find the index of the clicked panel
var index = $('#jdi_slider_control').children().index(this);
activatePanel(index);
});
});
相關問題
- 1. 尋找原型滑塊/旋轉木馬
- 2. 尋找響應式js旋轉木馬
- 3. 尋找一個JavaScript旋轉木馬
- 4. 旋轉木馬內的旋轉木馬
- 5. 引導旋轉木馬:旋轉木馬
- 6. 旋轉木馬
- 7. 旋轉木馬縮略圖,添加類到下一個旋轉木馬旋轉
- 8. 尋找一個特定的jquery旋轉木馬
- 9. 旋轉木馬博
- 10. jquery旋轉木馬
- 11. Papervision旋轉木馬
- 12. Bootstrap旋轉木馬
- 13. JavaScript旋轉木馬
- 14. iPhone - 旋轉木馬
- 15. 父級旋轉木馬裏面的兒童旋轉木馬js
- 16. 尋找BootStrap 3.0旋轉木馬照片庫
- 17. Bootstrap旋轉木馬控制旋轉木馬之外
- 18. 旋轉木馬 - 將不同頁面添加到旋轉木馬
- 19. 如何讓旋轉木馬滾動旋轉木馬Bootstrap
- 20. 圓形的ListView(類似於旋轉木馬的方式)
- 21. 添加類OWL的旋轉木馬afterLazyLoad
- 22. jQuery的旋轉木馬插件類似和打火機WowSlider
- 23. jQuery的3D旋轉木馬
- 24. WPF旋轉木馬/旋轉元件
- 25. 使Android旋轉木馬自動旋轉
- 26. 循環「活動」類與旋轉木馬
- 27. 旋轉木馬文本對齊
- 28. Bootsrap旋轉木馬文本不滑動
- 29. Umbraco旋轉木馬內容
- 30. 旋轉木馬滾動?