我想實現JQ UIslider - 但我一直遇到問題,所以我希望有人可以幫助。JQuery滑塊問題
我試圖做到沒有「滑塊」按鈕的JQUI圖像。我可以得到這麼多,但我無法讓它「正常」工作。我的代碼是這樣的:
HTML:
<div id="scroll-pane" class="clearfix" >
<div id="pagination" class="clearfix"></div>
<div class="scroll-bar-wrap">
<div class="scroll-bar"></div></div>
</div>
CSS:
.scroll-bar { background-color:#00FFFF; width: 50px; height: 20px; }
#pagination { width: 2440px; float: left; }
#scroll-pane { overflow: auto; width: 99%; float:left; }
.scroll-bar-wrap { clear: left; padding: 0 4px 0 2px; margin: 0 -1px -1px -1px; background: #FFCC00; width: 400px; }
.scroll-bar-wrap .ui-slider { border:0; height: 2em; margin: 0 auto; background: #FF0000; width: 20px;}
和JQ是這樣的:(順便說一句我一句都沒聽懂了吧!)
$(document).ready(function() {
var scrollPane = $("#scroll-pane"),
scrollContent = $("#pagination");
var scrollbar = $(".scroll-bar").slider({
slide: function(event, ui) {
if (scrollContent.width() > scrollPane.width()) {
scrollContent.css("margin-left", Math.round(
ui.value/100 * (scrollPane.width() - scrollContent.width())
) + "px");
} else {
scrollContent.css("margin-left", 0);
}
}
});
//append icon to handle
var handleHelper = scrollbar.find(".ui-slider-handle")
.mousedown(function() {
scrollbar.width(handleHelper.width());
})
.mouseup(function() {
scrollbar.width("100%");
})
.append("<span class='ui-icon ui-icon-grip-dotted-vertical'></span>")
.wrap("<div class='ui-handle-helper-parent'></div>").parent();
//change overflow to hidden now that slider handles the scrolling
scrollPane.css("overflow", "hidden");
//size scrollbar and handle proportionally to scroll distance
function sizeScrollbar() {
var remainder = scrollContent.width() - scrollPane.width();
var proportion = remainder/scrollContent.width();
var handleSize = scrollPane.width() - (proportion * scrollPane.width());
scrollbar.find(".ui-slider-handle").css({
width: handleSize,
"margin-left": -handleSize/2
});
handleHelper.width("").width(scrollbar.width() - handleSize);
}
//reset slider value based on scroll content position
function resetValue() {
var remainder = scrollPane.width() - scrollContent.width();
var leftVal = scrollContent.css("margin-left") === "auto" ? 0 :
parseInt(scrollContent.css("margin-left"));
var percentage = Math.round(leftVal/remainder * 100);
scrollbar.slider("value", percentage);
}
//if the slider is 100% and window gets larger, reveal content
function reflowContent() {
var showing = scrollContent.width() + parseInt(scrollContent.css("margin-left"), 10);
var gap = scrollPane.width() - showing;
if (gap > 0) {
scrollContent.css("margin-left", parseInt(scrollContent.css("margin-left"), 10) + gap);
}
}
//change handle position on window resize
$(window).resize(function() {
resetValue();
sizeScrollbar();
reflowContent();
});
//init scrollbar size
setTimeout(sizeScrollbar, 10);//safari wants a timeout
});
#pagination的內容是「動態」生成的。我的問題是,.scroll-bar-wrap .ui-slider
不滑動(動畫)。只是「觸摸它」會過度快速地移動幻燈片內容,很難「恢復」。
我需要的是一個「簡單滑塊情境」,其中#頁面向左/向右移動以在創建頁面時顯示/隱藏頁碼。有些東西告訴我JQUI代碼是「過於複雜」 - 我可能是錯的 - 但到目前爲止,這已經花費了很多時間在很簡單的事情上 - 好吧,我不是JQ/JS類型的人,但是。 。JQUI示例link text正常工作,這是它的代碼。我只是不希望背景/滑塊按鈕,因爲他們有它。