jquery 实现上下滚动效果示例代码
jquery 实现上下滚动效果示例代码
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:$(function(){varpage=1;vari=1;varconheight=$('.conli').height...

复制代码 代码如下:

<script type="text/javascript" src="script/jquery-1.7.2.min.js"></script>

<script type="text/javascript">

$(function() {

var page = 1;

var i = 1;

var conheight = $('.con li').height();

var lilen = $('li').length;

var len = Math.ceil( lilen / i );

alert(conheight+ " " + len);

//alert("page:"+page+" i:"+i+" conheight:"+conheight+" lilen:"+lilen+" len:"+len)

$('.next').click(function() {

if( page == len){

alert("已经到底不能再在操作!");

return false;

}

$('.con_list').animate({top:'-=' + conheight},'slow');

page++;

//if( page == len ) {

// $('.con_list').animate({top:0},'slow');

// page = 1;

// }else{

// $('.con_list').animate({top:'-=' + conheight},'slow');

// page++;

//}

});

$('.prev').click(function() {

if(page == 1){

alert("已经到头不能再进行操作!");

return false;

}

$('.con_list').animate({top:'+=' + conheight},'slow');

page--;

//if( page == 1 ) {

// $('.con_list').animate({top:'-=' + conheight*(len - 1)},'slow');

// page = len;

//}else{

// $('.con_list').animate({top:'+=' + conheight},'slow');

// page--;

//}

});

})

</script>

<style type="text/css">

* {

margin:0;padding:0

}

.prev,.next{

width:100px;height:20px;background:#333;cursor:pointer

}

.con{

width:100px;height:300px;overflow:hidden;position:relative

}

.con_list{

position:relative

}

.con li{

height:100px

}

.one{

background:#F90

}

.two {

background:#69C

}

.three{

background:#633

}

</style>

<body>

<div></div>

<div>

<div>

<ul>

<li>11111111111111111111</li>

<li>22222222222222222222</li>

<li>333333333333333333333</li>

<li>444444444444444444444</li>

<li>5555555555555555555555</li>

<li>6666666666666666666666666</li>

<li>7777777777777777777777777</li>

<li>88888888888888888888</li>

<li>99999999999999999999</li>

<li>10103000000000</li>

</ul>

</div>

</div>

<div></div>

</body>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类