您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js如何实现滑动门效果

2025/12/23 22:47:25发布17次查看
一、实现滑动门所需技术
1、简单的html基础知识
2、简单的css基础样式
3、基本的javascript知识
(推荐教程:javascript教程)
二、实现方法
html
<div id="container"> <img src="images/20190503222903.png"/><!--图片可以自己修改--> <img src="images/20190503222943.png"/> <img src="images/20190503223003.png"/> <img src="images/20190503223514.png"/></div>
css
*{ margin: 0; padding: 0; background-color: #ccc;}p{ text-align: center;}#container{ width: 1130px; height: 350px; margin: 0 auto; border-right:1px solid #ff0000; border-bottom:1px solid #ff0000; overflow: hidden; position: relative;}#container img{ width:500px; height:350px; display: block; position: absolute; border-bottm:1px solid #ff0000;}
js
//加载dom树window.onload = function(){//定义盒子var box=document.getelementbyid('container');//定义图片var imgs=box.getelementsbytagname('img');//图片宽度var imgwidth = imgs[0].offsetwidth;//隐藏宽度var exposewidth = 210;//盒子宽度var boxwidth = imgwidth + (imgs.length -1) * exposewidth;box.style.width='px';//设置每道门的初始位置function setimgspos(){for(var i = 1;i<imgs.length;i++){ imgs[i].style.left = imgwidth + exposewidth*(i -1)+ 'px'; } } setimgspos(); //计算每道门应该移动的距离 var translate = imgwidth - exposewidth; //为每道门绑定事件 for(var i=0;i<imgs.length;i++){ //使用立即调用的函数表达式,为了获得不同的i值 (function(i){ imgs[i].onmouseover = function(){ setimgspos(); //打开门 for(var j=1;j<=i;j++){ imgs[j].style.left = parseint(imgs[j].style.left,10) - translate + 'px'; } } })(i); } }
更多编程相关内容,请关注编程入门栏目!
以上就是js如何实现滑动门效果的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product