<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>小米4活动页面</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<style type="text/css">
body{
overflow: hidden;
}
#demo{
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: #000;
}
#img-a{
width: 1099px;
height: 569px;
background: url('img/fea-37.png') no-repeat;
margin-top: -264px;
margin-left: -914px;
left: 50%;
}
#img-b{
background: url('img/fea-38.png') no-repeat;
width: 1093px;
height: 608px;
margin-top: -223px;
margin-left: -184px;
left: 50%;
}
#sub{
position: absolute;
z-index: 2;
height: 100%;
width: 100%;
right: 0px;
background-color: #fff;
/* width: 0px; */
overflow: hidden;
}
.sub-a,.sub-b,#img-b,#img-a{
position: absolute;
top: 50%;
}
.sub-a{
width: 1102px;
height: 566px;
background: url('img/fea-35.png') no-repeat;
margin-top: -262px;
}
.sub-b{
width: 1096px;
height: 607px;
margin-top: -224px;
background: url("img/fea-36.png") no-repeat;
}
#bar{
position: absolute;
width: 42px;
height: 43px;
top: 50%;
margin-right: -21px;
background: url("img/fea-28.png") no-repeat;
z-index: 12;
cursor: move;
display: none;
}
</style>
</head>
<body>
<div id="demo">
<div id="img-a">
</div>
<div id="img-b">
</div>
<div id="sub">
<div class="sub-a">
</div>
<div class="sub-b">
</div>
</div>
<div id="bar">
</div>
</div>
<script type="text/javascript">
window.onload = function (){
var sub = document.getElementById("sub");
var div = sub.getElementsByTagName("div");
var imga = document.getElementById("img-a");
var imgb = document.getElementById("img-b");
var bar = document.getElementById("bar");
isMove = false;//是否拖动
OldX = 0;
// 初始化 位置
sub.style.width = Width() - 80 +'px';
div[0].style.right = Width()/2 + 914 - 1099 + 'px';
div[1].style.right = Width()/2 + 184 - 1096 + 'px';
bar.style.right = css(sub,"width");
// 初始化动画
act(sub,"width",0,function (){
act(sub,"width",(Width() - 80),function (){
bar.style.display = "block";
})
});
bar.onmousedown = function (event){
var event = event || window.event;
isMove = true;
OldX = event.clientX;
return false;
}
document.onmousemove = function (event){
var event = event || window.event;
if (isMove) {
var dirX = event.clientX - OldX;
sub.style.width = sub.offsetWidth - dirX + "px";
bar.style.right = css(sub,"width");
OldX = event.clientX;
}
return false;
}
document.onmouseup = function (){
isMove = false;
return false;
}
// 获得样式
function css(ele,attr){
if (ele.currentStyle) {
return ele.currentStyle[attr];
}else{
return getComputedStyle(ele, null)[attr];
}
}
// 动画和回调
function act(ele,attr,target,fn){
if (ele.timer) {
clearInterval(ele.timer);
}
ele.timer = setInterval(function (){
var cur = parseInt(css(ele,attr));
var speed = (target - cur)/5;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
ele.style[attr] = cur + speed + "px";
if (cur == target) {
clearInterval(ele.timer);
fn && fn();
}
},30)
}
// 显示器的宽高
function Width (){
return document.documentElement.clientWidth || document.body.clientWidth;
}
function Height(){
return document.documentElement.clientHeight || document.body.clientHeight;
}
}
</script>
</body>
</html>
js小米4活动页面效果实现
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...