鼠标滚轮滚动控制页面显示和页面动画
来源:互联网 发布:mac jenkins.war 启动 编辑:程序博客网 时间:2024/04/29 12:01
现在滚滚屏的效果几乎到处可见,下面我也来记录一组简单的滚滚屏效果,页面中,我只简单的添加了一个小动画。
页面结构:
<div class="container" id="container"> <div id="box"> <div class="con" id="one" style="z-index: 3"> <div class="test"> </div> </div> <div class="con" id="two"> <div class="test"> </div> </div> <div class="con" id="three"> <div class="test"> </div> </div> </div> <ol id="list" class="list"> </ol></div>
样式 :
<style> * { margin: 0px;; padding: 0px; list-style: none; } html, body { width: 100%; height: 100%; background-color: purple; } .container { width: 100%; height: 100%; position: relative; left: 0px; top: 0px; left: 0px; top: 0px; } .con { width: 100%; height: 100%; position: absolute; } .con .test { width: 100px; height: 100px; background-color: deeppink; position: absolute; left: 50%; top: 50%; margin-top: -50px; margin-left: -50px; } .con.active { transition: all 2s; } .con.active .test { animation: anim 2s; } @-webkit-keyframes anim { 0% { -webkit-transform: translateX(50px) scale(1.2)); -moz-transform: translateX(50px) scale(1.2); -ms-transform: translateX(50px) scale(1.2); -o-transform: translateX(50px) scale(1.2); transform: translateX(50px) scale(1.2); } 50% { -webkit-transform: translateX(0px) scale(.8); -moz-transform: translateX(0px) scale(.8); -ms-transform: translateX(0px) scale(.8); -o-transform: translateX(0px) scale(.8); transform: translateX(0px) scale(.8); } 100% { -webkit-transform: translateX(-50px); -moz-transform: translateX(-50px); -ms-transform: translateX(-50px); -o-transform: translateX(-50px); transform: translateX(-50px); } } @keyframes anim { 0% { -webkit-transform: translateX(50px) scale(1.2)); -moz-transform: translateX(50px) scale(1.2); -ms-transform: translateX(50px) scale(1.2); -o-transform: translateX(50px) scale(1.2); transform: translateX(50px) scale(1.2); } 50% { -webkit-transform: translateX(0px) scale(.8); -moz-transform: translateX(0px) scale(.8); -ms-transform: translateX(0px) scale(.8); -o-transform: translateX(0px) scale(.8); transform: translateX(0px) scale(.8); } 100% { -webkit-transform: translateX(-50px); -moz-transform: translateX(-50px); -ms-transform: translateX(-50px); -o-transform: translateX(-50px); transform: translateX(-50px); } } .container .list { position: absolute; right: 10px; top: 45%; z-index: 20; } .container .list li { width: 20px; height: 20px; border: 3px solid transparent; background-color: #fff; -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%; margin-bottom: 10px; opacity: 0.5; z-index: 20; } .container .list li.current { border: 3px solid #fff; background-color: #1c1c1c; opacity: 1; animation: point 1s 0.2s; } @keyframes point { 0% { transform: scale(.8); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } } </style>
js :
<script> var container = document.getElementById("container"); var list = document.getElementById("list"); var box = document.getElementById("box"); var cons = box.children; console.log(cons.length); var zIdx = 10; var nn = 0; var currentPosition = 0; //添加小圆点 var arr = ["red", "blue", "yellow"]; for (var i = 0; i < cons.length; i++) { cons[i].style.backgroundColor = arr[i]; var li = document.createElement("li"); list.appendChild(li); } list.children[0].className = "current"; //e.wheelDelta > 0滚轮向下滚动,e.wheelDelta < 0表示滚轮向上滚动 window.onmousewheel = function (e) { if (e.wheelDelta > 0) { currentPosition++; if (currentPosition > cons.length - 1) { currentPosition = 0; } for (var i = 0; i < cons.length; i++) { cons[i].style.zIndex = 1; list.children[i].className = ""; cons[i].className = "con"; } console.log(currentPosition); cons[currentPosition].style.zIndex = zIdx; cons[currentPosition].className = "con active"; list.children[currentPosition].className = "current"; } else { currentPosition--; if (currentPosition < 0) { currentPosition = cons.length - 1; } for (var i = 0; i < cons.length; i++) { cons[i].style.zIndex = 1; list.children[i].className = ""; cons[i].className = "con"; } console.log(currentPosition); cons[Math.abs(currentPosition)].style.zIndex = zIdx; cons[currentPosition].className = "con active"; list.children[Math.abs(currentPosition)].className = "current"; } }</script>
更多精彩请关注一下微信公众账号:
1 0
- 鼠标滚轮滚动控制页面显示和页面动画
- 鼠标滚轮控制页面滚动(山寨苹果官网iPhone5s的滚屏动画实例)
- 原生js利用鼠标滚轮实现滚动到当前页面实现动画效果
- 滚轮滚动时追加页面显示数据
- jQuery 控制页面滚动条显示和隐藏
- 滚动视图和页面控制
- 鼠标滚轮控制panel滚动条
- 鼠标滚轮控制panel滚动条
- 鼠标滚轮控制panel滚动条
- js获取页面中的鼠标滚轮事件
- WPF 使用鼠标滚轮控制ListBox水平滚动条滚动
- 控制IE页面滚动
- 鼠标滚轮滚动事件
- 相机跟随和鼠标滚轮控制缩放
- scrollReveal.js – 页面滚动显示动画JS
- scrollReveal.js – 页面滚动显示动画JS
- 鼠标上下滚动跳转页面。
- 用鼠标滚轮控制窗口上下滚动(原创)
- 自定义view圆
- 怎么在一个JSP页面打开时就加载servlet
- Java基础-IO流7 转换流特有功能
- 最短路径——dj+floyd+spfa(hdu2544)
- Ext.Loader
- 鼠标滚轮滚动控制页面显示和页面动画
- weblogic 清除jar缓存
- java读取properties 的最简单方式
- java http request&respone
- js 获取日期,获取今天,昨天,前天,两天内,三天内,四天内,五天内 日期函数
- jQuery弹出警告对话框美化插件(警告,确认和提示)
- Ural1090-In the Army Now
- TextView属性
- android 强大的模拟器之Genymotion