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

JS代码

  1. function $(id) { return document.getElementById(id); }
  2. //缓动轮播图
  3. var fhTimer;
  4. var fhNum = 0;
  5. var barNum = 0;
  6. fhTimer = setInterval(marquee, 20);
  7. function marquee() {
  8. fhNum--;
  9. barNum = fhNum;
  10. if(fhNum < -2400) {
  11. fhNum = 0;
  12. }
  13. $("fhc_ul").style.left = fhNum + "px";
  14. if(fhNum < -2400) {
  15. barNum = fhNum + 2400;
  16. }
  17. $("fhc_dBar").style.left = -(barNum / 2.75) + "px";
  18. }
  19. $("fhcShow").onmouseover = function() {
  20. $("fhc_d_box").style.display = "block";
  21. clearInterval(fhTimer);
  22. }
  23. $("fhc_d_box").onmouseover = function() {
  24. $("fhc_d_box").style.display = "block";
  25. }
  26. $("fhcShow").onmouseout = function() {
  27. $("fhc_d_box").style.display = "none";
  28. fhTimer = setInterval(marquee, 20);
  29. }
  30. //鼠标悬浮在标题也在暂停滚动
  31. $("fhTit").onmouseover = function() {
  32. clearInterval(fhTimer);
  33. }
  34. $("fhTit").onmouseout = function() {
  35. fhTimer = setInterval(marquee, 20);
  36. }
  37. //滑块
  38. $("fhc_dBar").onmousedown = function(event) {
  39. var event = event || window.event;
  40. var leftValue = event.clientX - this.offsetLeft;
  41. document.onmousemove = function(event) {
  42. var evt = event || window.event;
  43. var locationX = evt.clientX - leftValue;
  44. if(locationX < 0) {
  45. locationX = 0;
  46. }
  47. else if(locationX > 960 - 99) {
  48. locationX = 960 - 99;
  49. }
  50. $("fhc_dBar").style.left = locationX + "px";
  51. fhNum = -locationX * 2.75;
  52. //如果选中了,就取消选中,防止出现bug
  53. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  54. }
  55. document.onmouseup = function() {
  56. document.onmousemove = null;//取消注册的这个事件
  57. }
  58. }

HTML代码

  1. <div class="fxhh_ctt">
  2. <div class="fh_c_show" id="fhcShow">
  3. <ul class="fh_c_under" id="fhc_ul">
  4. <li><a href=" ">
  5. <p class="topTit">商品1</p>
  6. <img src="" alt="">
  7. </a></li>
  8. <li><a href=" ">
  9. <img src="" alt="">
  10. <p class="botTit">商品2</p>
  11. </a></li>
  12. <li><a href=" ">
  13. <p class="topTit">商品3</p>
  14. <img src="" alt="">
  15. </a></li>
  16. <li><a href=" ">
  17. <img src="" alt="">
  18. <p class="botTit">商品4</p>
  19. </a></li>
  20. <li><a href=" ">
  21. <p class="topTit">商品5</p>
  22. <img src="" alt="">
  23. </a></li>
  24. <li><a href=" ">
  25. <img src="" alt="">
  26. <p class="botTit">商品6</p>
  27. </a></li>
  28. <li><a href=" ">
  29. <p class="topTit">商品7</p>
  30. <img src="" alt="">
  31. </a></li>
  32. <li><a href=" ">
  33. <img src="" alt="">
  34. <p class="botTit">商品8</p>
  35. </a></li>
  36. <li><a href=" ">
  37. <p class="topTit">商品9</p>
  38. <img src="" alt="">
  39. </a></li>
  40. <li><a href=" ">
  41. <img src="" alt="">
  42. <p class="botTit">商品10</p>
  43. </a></li>
  44. <li><a href=" ">
  45. <p class="topTit">商品11</p>
  46. <img src="" alt="">
  47. </a></li>
  48. <li><a href=" ">
  49. <img src="" alt="">
  50. <p class="botTit">商品12</p>
  51. </a></li>
  52. <li><a href=" ">
  53. <p class="topTit">商品1</p>
  54. <img src="" alt="">
  55. </a></li>
  56. <li><a href=" ">
  57. <img src="" alt="">
  58. <p class="botTit">商品2</p>
  59. </a></li>
  60. <li><a href=" ">
  61. <p class="topTit">商品3</p>
  62. <img src="" alt="">
  63. </a></li>
  64. <li><a href=" ">
  65. <img src="" alt="">
  66. <p class="botTit">商品4</p>
  67. </a></li>
  68. <li><a href=" ">
  69. <p class="topTit">商品5</p>
  70. <img src="" alt="">
  71. </a></li>
  72. </ul>
  73. </div>
  74. <!-- 滑块 -->
  75. <div class="fhc_box" id="fhc_d_box">
  76. <div class="fhc_drop" id="fhc_dBar"></div>
  77. </div>
  78. <!-- 滑块end -->
  79. </div>

CSS代码

  1. .fxhh .fxhh_ctt {
  2. width: 990px;
  3. background-color: #fff;
  4. float: left;
  5. }
  6. .fxhh .fxhh_ctt .fh_c_show .fh_c_under img {
  7. width: 150px;
  8. height: 150px;
  9. }
  10. .fxhh .fxhh_ctt .fh_c_show {
  11. width: 990px;
  12. height: 260px;
  13. background-color: #fff;
  14. overflow: hidden;
  15. position: relative;
  16. }
  17. .fxhh .fxhh_ctt .fh_c_show .fh_c_under {
  18. width: 2000%;
  19. position: absolute;
  20. }
  21. .fxhh .fxhh_ctt .fh_c_show .fh_c_under li {
  22. float: left;
  23. text-align: center;
  24. width: 150px;
  25. height: 180px;
  26. margin-top: 40px;
  27. margin-right: 50px;
  28. }
  29. .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .topTit {
  30. margin-bottom: 10px;
  31. }
  32. .fxhh .fxhh_ctt .fh_c_show .fh_c_under li .botTit {
  33. margin-top: 10px;
  34. }
  35. .fxhh .fxhh_ctt .fhc_box {
  36. display: none;
  37. width: 960px;
  38. height: 4px;
  39. background-color: #f3f3f3;
  40. margin: 0 auto;
  41. position: absolute;
  42. top: 250px;
  43. left: 210px;
  44. }
  45. .fxhh .fxhh_ctt .fhc_drop {
  46. width: 99px;
  47. height: 9px;
  48. border-radius: 4px;
  49. background-color: #d8d8d8;
  50. position: absolute;
  51. top: -3px;
  52. }

JS实现可用滑块滑动的缓动图的更多相关文章

  1. JS实现div的抖动:缓动式抖动

    代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...

  2. 《JavaScript 实战》:Tween 算法及缓动效果

    Flash 做动画时会用到 Tween 类,利用它可以做很多动画效果,例如缓动.弹簧等等.我这里要教大家的是怎么利用 Flash 的 Tween 类的算法,来做js的Tween算法,并利用它做一些简单 ...

  3. 利用tween.js算法生成缓动效果

    在讲tween类之前,不得不提的是贝塞尔曲线了.首先,贝塞尔曲线是指依据四个位置任意的点坐标绘制出的一条光滑曲线.它在作图工具或动画中中运用得比较多,例如PS中的钢笔工具,firework中的画笔等等 ...

  4. JS —— 轮播图中的缓动函数的封装

    轮播图的根本其实就是缓动函数的封装,如果说轮播图是一辆跑动的汽车,那么缓动函数就是它的发动机,今天本文章就带大家由简入繁,封装属于自己的缓动函数~~ 我们从需求的角度开始,首先给出一个简单需求: 1. ...

  5. window.requestAnimationFrame与Tween.js配合使用实现动画缓动效果

    window.requestAnimationFrame 概述 window.requestAnimationFrame()这个方法是用来在页面重绘之前,通知浏览器调用一个指定的函数,以满足开发者操作 ...

  6. GSAP JS基础教程--使用缓动函数

    今天来了解一下缓动easeing函数. 开始,如果你还没有GSAP的类包,可以到GreenSock的官网去下载最新版本的类包,或者直接点击这里​来下载 学习之前,先来准备一下:     <!DO ...

  7. JS特效@缓动框架封装及应用

    | 版权声明:本文为博主原创文章,未经博主允许不得转载. 一.变量CSS样式属性获取/赋值方法 给属性赋值:(既能获取又能赋值) 1)div.style.width 单个赋值:点语法,这个方法比较固定 ...

  8. tween.js缓动(补间动画)

    一.理解tween.js 如果看到上面的已经理解了,可以跳过下面的部分.下面为对Tween.js的解释 下面就介绍如何使用这个Tween了,首先b.c.d三个参数(即初始值,变化量,持续时间)在缓动开 ...

  9. JS动画之缓动函数分析及动画库

    上一篇讲了JS动画定时器相关知识,这一篇介绍下缓动函数及流行的动画库. 熟悉的图 实际使用 jquery animate()+jquery.easing插件的使用: $(selector).anima ...

随机推荐

  1. UDP如何实现可靠传输

    概述 UDP不属于连接协议,具有资源消耗少,处理速度快的优点,所以通常音频,视频和普通数据在传送时,使用UDP较多,因为即使丢失少量的包,也不会对接受结果产生较大的影响. 传输层无法保证数据的可靠传输 ...

  2. Cheat Engine TUTORIAL 教程 (8个步骤)

    https://www.cnblogs.com/ae6623/archive/2011/04/16/4416874.html https://www.52pojie.cn/thread-828030- ...

  3. input标签type="file"上传文件的css样式

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 5+app uni-app flutter

    5+app uni-app flutter三者区别是什么? - 知乎 https://www.zhihu.com/question/295107584/answer/525442299 崔红保 DCl ...

  5. Linux下java进程CPU占用率高分析方法(二)

    1. 通过 top 命令查看当前系统CPU使用情况,定位CPU使用率超过100%的进程ID:2. 通过 ps aux | grep PID 命令进一步确定具体的线程信息:3. 通过 ps -mp pi ...

  6. percona-mysql5.7.24使用xtrabackup工具配置主从同步

    主从配置详细过程: 环境准备: 配置好服务器,主从服务器都安装并启动mysql数据库 # 添加读写账号和只读账号,应用配置中,写主库用读写账号,统计从库数据yoga只读账号 grant select, ...

  7. shell编程系列3--命令替换

    shell编程系列3--命令替换 命令替换 命令替换总结 方法1 `command` 方法2 $(command) 例子1: 获取系统的所有用户并输出 for循环能以空格.换行.tab键作为分隔符 [ ...

  8. Python3基础 函数 参数为list 使用+=会影响到外部的实参

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  9. Laya和白鹭的高亮文字 (textFlow)

    版本2.1.1.1 游戏中用的高亮文字,例如下图 "使用 2钻石 可获得金币",2钻石是不同颜色高亮的. 白鹭的高亮文字有文本样式 txt.textFlow = <Array ...

  10. Flink assignAscendingTimestamps 生成水印的三个重载方法

    先简单介绍一下Timestamp 和Watermark 的概念: 1. Timestamp和Watermark都是基于事件的时间字段生成的 2. Timestamp和Watermark是两个不同的东西 ...