JS实现可用滑块滑动的缓动图代码
网络编程 2021-07-04 15:51www.168986.cn编程入门
这篇文章主要介绍了JS实现可用滑块滑动的缓动图代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
尝试模仿京东的“发现好货”模块的可用滑块滑动的缓动图
JS代码
function $(id) { return document.getElementById(id); } //缓动轮播图 var fhTimer; var fhNum = 0; var barNum = 0; fhTimer = setInterval(marquee, 20); function marquee() { fhNum--; barNum = fhNum; if(fhNum < -2400) { fhNum = 0; } $("fhc_ul").style.left = fhNum + "px"; if(fhNum < -2400) { barNum = fhNum + 2400; } $("fhc_dBar").style.left = -(barNum / 2.75) + "px"; } $("fhcShow").onmouseover = function() { $("fhc_d_box").style.display = "block"; clearInterval(fhTimer); } $("fhc_d_box").onmouseover = function() { $("fhc_d_box").style.display = "block"; } $("fhcShow").onmouseout = function() { $("fhc_d_box").style.display = "none"; fhTimer = setInterval(marquee, 20); } //鼠标悬浮在标题也在暂停滚动 $("fhTit").onmouseover = function() { clearInterval(fhTimer); } $("fhTit").onmouseout = function() { fhTimer = setInterval(marquee, 20); } //滑块 $("fhc_dBar").onmousedown = function(event) { var event = event || window.event; var leftValue = event.clientX - this.offsetLeft; document.onmousemove = function(event) { var evt = event || window.event; var locationX = evt.clientX - leftValue; if(locationX < 0) { locationX = 0; } else if(locationX > 960 - 99) { locationX = 960 - 99; } $("fhc_dBar").style.left = locationX + "px"; fhNum = -locationX 2.75; //如果选中了,就取消选中,防止出现bug window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); } document.onmouseup = function() { document.onmousemove = null;//取消注册的这个事件 } }
HTML代码
<div class="fxhh_ctt"> <div class="fh_c_show" id="fhcShow"> <ul class="fh_c_under" id="fhc_ul"> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品1</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品2</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品3</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品4</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品5</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品6</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品7</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品8</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品9</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品10</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品11</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品12</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品1</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品2</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品3</p> <img src="" alt=""> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img src="" alt=""> <p class="botTit">商品4</p> </a></li> <li><a href=" " rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <p class="Tit">商品5</p> <img src="" alt=""> </a></li> </ul> </div> <!-- 滑块 --> <div class="fhc_box" id="fhc_d_box"> <div class="fhc_drop" id="fhc_dBar"></div> </div> <!-- 滑块end --> </div> CSS代码 .fxhh .fxhh_ctt { width: 990px; background-color: #fff; float: left; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under img { width: 150px; height: 150px; } .fxhh .fxhh_ctt .fh_c_show { width: 990px; height: 260px; background-color: #fff; overflow: hidden; position: relative; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under { width: 2000%; position: absolute; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under li { float: left; text-align: center; width: 150px; height: 180px; margin-: 40px; margin-right: 50px; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .Tit { margin-bottom: 10px; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .botTit { margin-: 10px; } .fxhh .fxhh_ctt .fhc_box { display: none; width: 960px; height: 4px; background-color: #f3f3f3; margin: 0 auto; position: absolute; : 250px; left: 210px; } .fxhh .fxhh_ctt .fhc_drop { width: 99px; height: 9px; border-radius: 4px; background-color: #d8d8d8; position: absolute; : -3px; }
以上所述是长沙网络推广给大家介绍的JS实现可用滑块滑动的缓动图代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,长沙网络推广会及时回复大家的!
上一篇:微信小程序获取位置展示地图并标注信息的实例
下一篇:vue动态子组件的两种实现方式
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程