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=" ">
<p class="topTit">商品1</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品2</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品3</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品4</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品5</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品6</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品7</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品8</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品9</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品10</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品11</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品12</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品1</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品2</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品3</p>
<img src="" alt="">
</a></li>
<li><a href=" ">
<img src="" alt="">
<p class="botTit">商品4</p>
</a></li>
<li><a href=" ">
<p class="topTit">商品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-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实现div的抖动:缓动式抖动
代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- 《JavaScript 实战》:Tween 算法及缓动效果
Flash 做动画时会用到 Tween 类,利用它可以做很多动画效果,例如缓动.弹簧等等.我这里要教大家的是怎么利用 Flash 的 Tween 类的算法,来做js的Tween算法,并利用它做一些简单 ...
- 利用tween.js算法生成缓动效果
在讲tween类之前,不得不提的是贝塞尔曲线了.首先,贝塞尔曲线是指依据四个位置任意的点坐标绘制出的一条光滑曲线.它在作图工具或动画中中运用得比较多,例如PS中的钢笔工具,firework中的画笔等等 ...
- JS —— 轮播图中的缓动函数的封装
轮播图的根本其实就是缓动函数的封装,如果说轮播图是一辆跑动的汽车,那么缓动函数就是它的发动机,今天本文章就带大家由简入繁,封装属于自己的缓动函数~~ 我们从需求的角度开始,首先给出一个简单需求: 1. ...
- window.requestAnimationFrame与Tween.js配合使用实现动画缓动效果
window.requestAnimationFrame 概述 window.requestAnimationFrame()这个方法是用来在页面重绘之前,通知浏览器调用一个指定的函数,以满足开发者操作 ...
- GSAP JS基础教程--使用缓动函数
今天来了解一下缓动easeing函数. 开始,如果你还没有GSAP的类包,可以到GreenSock的官网去下载最新版本的类包,或者直接点击这里来下载 学习之前,先来准备一下: <!DO ...
- JS特效@缓动框架封装及应用
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 一.变量CSS样式属性获取/赋值方法 给属性赋值:(既能获取又能赋值) 1)div.style.width 单个赋值:点语法,这个方法比较固定 ...
- tween.js缓动(补间动画)
一.理解tween.js 如果看到上面的已经理解了,可以跳过下面的部分.下面为对Tween.js的解释 下面就介绍如何使用这个Tween了,首先b.c.d三个参数(即初始值,变化量,持续时间)在缓动开 ...
- JS动画之缓动函数分析及动画库
上一篇讲了JS动画定时器相关知识,这一篇介绍下缓动函数及流行的动画库. 熟悉的图 实际使用 jquery animate()+jquery.easing插件的使用: $(selector).anima ...
随机推荐
- Java设计模式之一单例模式
什么是单例模式 保证一个系统中的某个类只有一个实例而且该实例易于外界访问.例如Windows界面的任务管理器就可以看做是一个单例. 单例模式的使用场景 需要频繁的进行创建和销毁的对象: 创建对象时耗时 ...
- Python-matplotlib画图(莫烦笔记)
https://www.zhihu.com/collection/260736383 https://blog.csdn.net/gaotihong/article/details/80983937 ...
- NPVariant -js传递给NPAPI插件参数在firefox和chrome需要采用不同的获取方式
原帖地址:http://blog.sina.com.cn/s/blog_4c6631790102wd1o.html 整数参数 typedef struct _NPVariant { NPVariant ...
- 从Windows命令行启动MySQL
SERVER: 从Windows命令行启动MySQL 可以从命令行手动启动MySQL服务器.可以在任何版本的Windows中实现. 要想从命令行启动mysqld服务器,你应当启动控制台窗口(或“DOS ...
- 5+app uni-app flutter
5+app uni-app flutter三者区别是什么? - 知乎 https://www.zhihu.com/question/295107584/answer/525442299 崔红保 DCl ...
- Flutter的运行环境标识
Flutter的四种运行模式:Debug.Release.Profile和test ,在实际开发中,我们往往需要根据当前运行模式的不同,选择不同的操作,比如在Debug模式启用Log.在生产模式关闭L ...
- openresty开发系列13--lua基础语法2常用数据类型介绍
openresty开发系列13--lua基础语法2常用数据类型介绍 一)boolean(布尔)布尔类型,可选值 true/false: Lua 中 nil 和 false 为"假" ...
- Qt编写气体安全管理系统20-控制器管理
一.前言 控制器管理,主要就是对控制器进行添加删除和修改,其中包括编号.端口名称.控制器名称.控制器地址.控制器型号.探测器数量这几个字段,端口名称表示当前控制器所属哪个端口,一个系统中可以有好多个端 ...
- KSQL Syntax Reference
KSQL Syntax Reference KSQL has similar semantics to SQL: Terminate KSQL statements with a semicolon ...
- Day3作业:ha_proxy配置文件修改
不废话,上代码 readme: # Auther:ccorz Mail:ccniubi@163.com Blog:http://www.cnblogs.com/ccorz/ # GitHub:http ...