资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

JS如何实现可用滑块滑动的缓动

这篇文章主要介绍了JS如何实现可用滑块滑动的缓动,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

成都创新互联成都企业网站建设服务,提供成都做网站、成都网站设计网站开发,网站定制,建网站,网站搭建,网站设计,响应式网站设计,网页设计师打造企业风格网站,提供周到的售前咨询和贴心的售后服务。欢迎咨询做网站需要多少钱:13518219792

尝试模仿京东的“发现好货”模块的可用滑块滑动的缓动图

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代码


  
    
      
  •         商品1

                   
  •       
  •                  商品2

          
  •       
  •         商品3

                   
  •       
  •                  商品4

          
  •       
  •         商品5

                   
  •       
  •                  商品6

          
  •       
  •         商品7

                   
  •       
  •                  商品8

          
  •       
  •         商品9

                   
  •       
  •                  商品10

          
  •       
  •         商品11

                   
  •       
  •                  商品12

          
  •       
  •         商品1

                   
  •       
  •                  商品2

          
  •       
  •         商品3

                   
  •       
  •                  商品4

          
  •       
  •         商品5

                   
  •        
              
      
       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-top: 40px;   margin-right: 50px; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .topTit {   margin-bottom: 10px; } .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .botTit {   margin-top: 10px; } .fxhh .fxhh_ctt .fhc_box {   display: none;   width: 960px;   height: 4px;   background-color: #f3f3f3;   margin: 0 auto;   position: absolute;   top: 250px;   left: 210px; } .fxhh .fxhh_ctt .fhc_drop {   width: 99px;   height: 9px;   border-radius: 4px;   background-color: #d8d8d8;   position: absolute;   top: -3px; }

    感谢你能够认真阅读完这篇文章,希望小编分享的“JS如何实现可用滑块滑动的缓动”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!


    分享标题:JS如何实现可用滑块滑动的缓动
    标题网址:http://cdkjz.cn/article/gjehsc.html
    返回首页 了解更多建站资讯
    多年建站经验

    多一份参考,总有益处

    联系快上网,免费获得专属《策划方案》及报价

    咨询相关问题或预约面谈,可以通过以下方式与我们联系

    业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220