点击上下移动
2017-01-15 00:00
190 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
* {
padding: 0;
margin: 0;
}
.content {
margin-top: 80px;
}
.box {
width: 100px;
height: 600px;
border: 1px solid #000;
overflow: hidden;
}
ul {
list-style: none;
}
.top {
width: 100px;
height: 30px;
margin-bottom: 10px;
background-color: #FF4500;
text-align: center;
color: #fff;
}
.bottom {
width: 100px;
height: 30px;
margin-top: 10px;
background-color: slateblue;
text-align: center;
color: #fff;
}
.content_ul {
width: 100%;
}
.li {
width: 100%;
height: 100px;
text-align: center;
font-size: 2rem;
color: #fff;
}
.li:nth-of-type(odd) {
background: #ff0000;
}
.li:nth-of-type(even) {
background: #0000ff;
}
</style>
</head>
<body>
<div class="content">
<div class="top">TOP</div>
<div class="box">
<ul class="content_ul">
<li class="li">1</li>
<li class="li">2</li>
<li class="li">3</li>
<li class="li">4</li>
<li class="li">5</li>
<li class="li">6</li>
<li class="li">7</li>
<li class="li">8</li>
</ul>
</div>
<div class="bottom">bottom</div>
</div>
</body>
</html>
<script>
$(function() {
var a = 0;
var c = 100;
$(".bottom ").click(function() {
var box_coordinate = $(".box").offset(); //获取固定的盒子坐标
var li_coordinate = $(".li:first").offset(); //获取第一个值的坐标
var top = li_coordinate.top;
if(parseInt(top)!= parseInt(box_coordinate.top + 1)) {
a += c;
$(".content_ul").css("margin-top", a)
} else {
alert("已经到顶了哦")
}
})
$(".top").click(function() {
var box_coordinate = $(".box").offset(); //获取固定的盒子坐标
var li_coordinate = $(".li:last").offset(); //获取最后一个值
var top = li_coordinate.top;
var height = $(".box").css("height");
height = parseInt(height);
if(parseInt(top) >= parseInt(height + box_coordinate.top +1) ) {
a -= c;
$(".content_ul").css("margin-top", a)
} else {
alert("已经到底了哦")
}
})
})
</script>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
* {
padding: 0;
margin: 0;
}
.content {
margin-top: 80px;
}
.box {
width: 100px;
height: 600px;
border: 1px solid #000;
overflow: hidden;
}
ul {
list-style: none;
}
.top {
width: 100px;
height: 30px;
margin-bottom: 10px;
background-color: #FF4500;
text-align: center;
color: #fff;
}
.bottom {
width: 100px;
height: 30px;
margin-top: 10px;
background-color: slateblue;
text-align: center;
color: #fff;
}
.content_ul {
width: 100%;
}
.li {
width: 100%;
height: 100px;
text-align: center;
font-size: 2rem;
color: #fff;
}
.li:nth-of-type(odd) {
background: #ff0000;
}
.li:nth-of-type(even) {
background: #0000ff;
}
</style>
</head>
<body>
<div class="content">
<div class="top">TOP</div>
<div class="box">
<ul class="content_ul">
<li class="li">1</li>
<li class="li">2</li>
<li class="li">3</li>
<li class="li">4</li>
<li class="li">5</li>
<li class="li">6</li>
<li class="li">7</li>
<li class="li">8</li>
</ul>
</div>
<div class="bottom">bottom</div>
</div>
</body>
</html>
<script>
$(function() {
var a = 0;
var c = 100;
$(".bottom ").click(function() {
var box_coordinate = $(".box").offset(); //获取固定的盒子坐标
var li_coordinate = $(".li:first").offset(); //获取第一个值的坐标
var top = li_coordinate.top;
if(parseInt(top)!= parseInt(box_coordinate.top + 1)) {
a += c;
$(".content_ul").css("margin-top", a)
} else {
alert("已经到顶了哦")
}
})
$(".top").click(function() {
var box_coordinate = $(".box").offset(); //获取固定的盒子坐标
var li_coordinate = $(".li:last").offset(); //获取最后一个值
var top = li_coordinate.top;
var height = $(".box").css("height");
height = parseInt(height);
if(parseInt(top) >= parseInt(height + box_coordinate.top +1) ) {
a -= c;
$(".content_ul").css("margin-top", a)
} else {
alert("已经到底了哦")
}
})
})
</script>
相关文章推荐
- 点击top回滚到顶部和窗口浮动跟随鼠标上下移动
- 移动web端<input type="number">手机上点击直接打开数字键盘,并修改样式去除最右端上下箭头
- 点击上下左右按钮让背景上下左右移动
- 《跑跑跑》(四)——添加屏幕点击事件,让主角上下移动
- Javascript控制Listbox左右/上下移动方法集合
- CocosCreator中使玩家移动到点击位置的代码
- java 列表数据上下移动或置顶
- iOS界面不能点击(tableView 的cell 不能使用点击事件,tableView也不能上下滚动)
- APP中常见上下循环滚动通知的简单实现,点击可进入详情
- Android 控件的显示隐藏上下左右移动动画
- Html点击按钮上下逐条滚动,外层div不遮挡内层div内容
- WINCE下模拟鼠标点击,移动
- jQuery实现百度图片移入移出内容提示框上下左右移动的效果
- 常见右侧广告,可上下移动
- div+css 上下左右移动
- js控制select 中option项的上下移动
- 用自定义按钮控制multiple型select元素的上下移动
- emacs中配置上下移动行
- Lenovo笔记本各类型触控板,触摸部分只能移动无法点击的问题汇总
- 红旗办Midinux峰会 携上下游厂商共促移动互联网