css3完成可拖动自动跳转的分页查询软件示例

2021-01-20 09:13 jianzhan

今日我要向大伙儿共享1款很非常的CSS3分页查询软件,这款分页查询软件不但能够点一下分页查询按钮来完成分页查询,并且能够拖动滑杆来完成随意网页页面的自动跳转,看看都十分酷,很合适1些个性化化的本人网站应用,自然,这款分页查询软件也合适ajax换页,实际效果都挺非常好的。先看来看实际效果图:


如何,还挺酷的吧。

自然你还可以在这里查询软件的DEMO演试。

接下来大家来共享1下源代码的完成思路,这里用到了jQuery UI架构,这么酷的滑杆是靠它完成的,要不然,写的累死。。

最先是HTML编码:


拷贝编码
编码以下:

<div class="pageSlider long"></div>
<form class="pageForm" action="#">
<label class="pageLabel" for="pageInput">
Page number you'd like to go to. (Max of 30)
</label>
<a
class="pagePrev pageSkip"
href="#?page=6"
title="Previous Page (6)">Previous Page</a>
<input id="pageInput" class="pageInput"
type="text" maxlength="3" placeholder="#">
<a
class="pageNext pageSkip"
href="#?page=8"
title="Next Page (8)">Next Page</a>
<button class="pageButton"
title="Go to chosen page of results">Go</button>
</form>


这里大家看到,起先界定了滑杆的地区,随后是两个分页查询按钮,能够向前翻和向后翻,最终是1个随意页自动跳转的页码键入框和1个按钮。

别看这个滑杆很好看,会很难完成,实际上运用jQuery UI这个物品十分简易。

接下看来看CSS编码:

前后左右换页按钮:


拷贝编码
编码以下:

.pageSkip {
display: inline-block;
background: transparent url('css/monotone_arrow_left_small.png') no-repeat ⑴0px ⑴0px;
text-indent: ⑼99em;
background-size: 40px;
opacity: 0.7;
vertical-align: middle;
width: 20px;
height: 20px;
}
.pageNext {
background-image: url('css/monotone_arrow_right.png');
}

很遗憾,运用了两张箭头照片做为情况,但是,实际效果也还能够。

随后是键入框:


拷贝编码
编码以下:

.pageNumber {
position: relative;
top: ⑶8px;
left: 50%;
font-size: 12px;
color: #333;
width: 60px;
display: block;
text-align: center;
margin-left: ⑴7px;
background: white;
padding: 5px 10px;
border-radius: 3px;
box-shadow: 0 0 5px rgba(151, 38, 20, 0.15);
}
.pageNumber:after {
content: " ";
display: block;
position: absolute;
width: 0;
height: 0;
top: 24px;
border: 6px solid transparent;
border-top-color: white;
}

随后是滑杆的情况,运用了CSS3线形渐变色特性:


拷贝编码
编码以下:

.ui-slider-horizontal {
width: 60%;
height: 6px;
top: 0px;
margin: 0px 10px 2px;
border-radius: 6px;
position: relative;
display: inline-block;
background: #F46652;
background-image: repeating-linear-gradient(28deg, transparent, transparent 10px, #dd5846 10px, #dd5846 20px);
box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.4);
}
.ui-slider-horizontal:before {
content: " ";
position: absolute;
width: auto;
height: 16px;
top: ⑸px;
left: ⑷px;
right: ⑷px;
border-radius: 10px;
z-index: ⑴;
background: linear-gradient(rgba(0, 0, 0, 0.1) 0%, rgba(255, 255, 255, 0.8) 90%);
}
.ui-slider.long .ui-slider-handle {
height: 12px;
width: 30px;
background: #f1f1f1;
display: block;
position: absolute;
border-radius: 50px;
margin-top: ⑶px;
margin-left: ⑴5px;
text-decoration: none;
background: #f5f5f5;
background: linear-gradient(#f5f5f5 0%, #cccccc 100%);
box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.35), 0 0 2px 1px rgba(0, 0, 0, 0.15), 0 3px 3px rgba(0, 0, 0, 0.2), 0 7px 5px rgba(0, 0, 0, 0.1), 0 11px 10px rgba(0, 0, 0, 0.1);
}
.ui-slider.long .ui-slider-handle::before,
.ui-slider.long .ui-slider-handle::after {
content: " ";
width: 2px;
height: 40%;
position: absolute;
background: transparent;
border-radius: 0px;
box-shadow: ⑴px 0px 0px rgba(255, 255, 255, 0.8), 1px 0px 0px rgba(255, 255, 255, 0.8), 2px 0 0 rgba(0, 0, 0, 0.3), 1px 0 0 rgba(0, 0, 0, 0.3) inset;
}
.ui-slider.long .ui-slider-handle::before {
left: 10px;
top: 30%;
}
.ui-slider.long .ui-slider-handle::after {
right: 12px;
top: 30%;
}
@media (max-width: 550px) {
.pagination {
width: auto;
}
.pageForm {
display: block;
margin-top: 20px;
}
.pageInput {
margin: 0;
}
.pageSlider {
width: 260px;
margin: 0 15px;
}
}

最终是js,这是用来完成换页逻辑性的,看来看:

拷贝编码
编码以下:

$(document).ready( function() {
var pagesMax = 30;
var pagesMin = 1;
var startPage = 7;
var url = "<a href="http://yoe.com/results?page={{1">http://yoe.com/results?page={{1</a>}}";
$('.pagination .pageSlider').slider({
value: startPage, max: pagesMax, min: pagesMin,
animate: true,
create: function( event, ui ) {
$('.pagination .pageSlider .ui-slider-handle').attr({
"aria-valuenow": startPage,
"aria-valuetext": "Page " + startPage,
"role": "slider",
"aria-valuemin": pagesMin,
"aria-valuemax": pagesMax,
"aria-describedby": "pageSliderDescription"
});
$('.pagination .pageInput').val( startPage );
}
}).on( 'slide', function(event,ui) {
// let user skip 10 pages with keyboard ;)
if( event.metaKey || event.ctrlKey ) {
if( ui.value > $(this).slider('value') ) {
if( ui.value+9 < pagesMax ) { ui.value+=9; }
else { ui.value=pagesMax }
$(this).slider('value',ui.value);
} else {
if( ui.value⑼ > pagesMin ) { ui.value-=9; }
else { ui.value=pagesMin }
$(this).slider('value',ui.value);
}
event.preventDefault();
}
$('.pagination .pageNumber span').text( ui.value );
$('.pagination .pageInput').val( ui.value );
}).on('slidechange', function(event, ui) {
$('.pagination .pageNumber')
.attr('role','alert')
.find('span')
.text( ui.value );
$('.pagination .pageInput').val( ui.value );
$('.pagination .pageSlider .ui-slider-handle').attr({
"aria-valuenow": ui.value,
"aria-valuetext": "Page " + ui.value
});
});
$('.pagination.pageSlider.ui-slider-handle').on('keyup',function(e){
if(e.which==13){
varcurPage=$('.pagination.pageSlider').slider('value');
alert('wewouldnowsendyouto:'+url.replace(/{{.}}/,curPage));
}
});
$('.pagination.pageInput').on('change',function(e){
$('.pagination.pageSlider').slider('value',$(this).val());
});
vartmr;
$('.pageSkip').on('click',function(e){
e.preventDefault();
var$this=$(this);
if($this.hasClass('pageNext')){
varcurPage=$('.pagination.pageSlider').slider('value')+1;
}elseif($this.hasClass('pagePrev')){
varcurPage=$('.pagination.pageSlider').slider('value')⑴;
}
$('.pagination.pageSlider').slider('value',curPage);
clearTimeout(tmr);
tmr=setTimeout(function(){
alert('wewouldnowsendyouto:'+url.replace(/{{.}}/,curPage));
},1000);
});
functionsliderPips(min,max){
varpips=max-min;
var$pagination=$('.pagination.pageSlider');
for(i=0;i<=pips;i++){
vars=$('<spanclass="pagePip"/>').css({
left:''+(100/pips)*i+'%'
});
$pagination.append(s);
}
varminPip=$('<spanclass="pageMinPip">'+min+'</span>');
varmaxPip=$('<spanclass="pageMaxPip">'+max+'</span>');
$pagination.prepend(minPip,maxPip);
};
sliderPips(pagesMin,pagesMax);
functionsliderLabel(){
$('.pagination.ui-slider-handle').append(
'<spanclass="pageNumber">Page<span>'+
$('.pagination.pageSlider').slider('value')+
'</span></span>');
};
sliderLabel();
$('.pagination.pageButton').on('click',function(e){
e.preventDefault();
varcurPage=$('.pagination.pageSlider').slider('value');
alert('wewouldnowsendyouto:'+
url.replace(/{{.}}/,curPage));
});
});