原生jsfor拼接html,原生js滚滚屏.html

*{

margin: 0;

padding: 0;

}

html,body{

width: 100%;

height: 100%;

overflow: hidden;

}

.container{

width: 100%;

height: 100%;

position: absolute;

top: 0;

left: 0;

transition: all 1s ease 0s;

}

.page{

width: 100%;

height: 100%;

background: yellowgreen;

}

.page0{background-color: yellowgreen;}

.page1{background-color: orange;}

.page2{background-color: skyblue;}

.page3{background-color: gold;}

.page4{background-color: rgb(111,222,123);}

.circles{

width: 15px;

height: 100px;

position: fixed;

right: 10px;

top: 50%;

margin-top: -50px;

/*background-color: red;*/

}

.circles span{

display: inline-block;

width: 15px;

height: 15px;

border-radius: 50%;

background-color: yellow;

font-size: 12px;

text-align: center;

line-height: 15px;

margin-bottom: 5px;

cursor: pointer;

}

.circles span.cur{

background-color: red;

}

0

1

2

3

4

0

1

2

3

4

var container=document.getElementById("container");

//获取所有的焦点

var circles=document.getElementById("circles").children;

//信号量

var idx=0;

//函数节流防止化的太快

var lock=true;

//事件处理函数;

function mousewheelhandler(event){

event=event||window.event;

//节流:

if(!lock){

return;

}

//阻止默认事件

if(event.preventDefault){

event.preventDefault();

}

else{

event.returnValue=false;

}

//chrome,ie用的是event。wheeldelta;

if(event.wheelDelta){

var direction=event.wheelDelta>0?1:-1;

}

else if(event.detail){

//火狐用的是event.detail;

var direction=event.detail>0?-1:1;

}

//滚轮往下滚,-(-1) 就是加一;

idx-=direction;

if(idx<0){

idx=0;

}

else if(idx>4){

idx=4;

}

//设置小圆点

//将所有的小圆点清空

for(var i=0;i

circles[i].className='';

}

//将制定的小圆点的名字,让其背景颜色

circles[idx].className="cur";

container.style.top=-idx*100+"%";

//上锁

lock=false;

//模拟等待1.5秒后开锁,才可以继续滚动

setTimeout(function(){

//解锁

lock=true;

},1000)

}

//这里不用根据不同的浏览器进行判断,这是因为事件添加了如果浏览器不认识,不报错了

//给ie,chrome添加事件

document.onmousewheel=mousewheelhandler;

try{

//给火狐添加事件

document.addEventListener("DOMMouseScroll",mousewheehandler,false);

}

catch(err){

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值