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 ...
随机推荐
- 关于SQL中的ROWNUM问题
前言 昨天改小程序的后台,看见之前写的分页很奇怪,startIndex和endIndex两个下标, endIndex 总是在里面层,而startIndex总是在外层,我随后改了,直接Where row ...
- include mime.types;
include mime.types; (index):1 Resource interpreted as Stylesheet but transferred with MIME type appl ...
- eclipse remote system explorer operation
Remote System Explorer Operation卡死Eclipse解决方案 - 披萨大叔的博客 - CSDN博客https://blog.csdn.net/qq_27258799/ar ...
- springboot rabbitMQ 死信对列 实现消息的可靠消费
1 引入 maven 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifac ...
- linux安装上传下载工具lrszs
普通用户下使用sudo获取root权限,root用户直接安装: [mall@VM_0_7_centos ~]$ sudo yum -y install lrzsz Loaded plugins: fa ...
- 【Tomcat】Tomcat 原理架构(一)
Tomcat是什么 开源的 Java Web 应用服务器,实现了 Java EE(Java Platform Enterprise Edition)的部 分技术规范,比如 Java Servlet.J ...
- 转 zabbix 优化方法 以及 后台数据库查询方法 两则
############sample 1 https://blog.51cto.com/sfzhang88/1558254 如何从Zabbix数据库中获取监控数据 sfzhang关注6人评论40627 ...
- pytorch 中Dataloader中的collate_fn参数
一般的,默认的collate_fn函数是要求一个batch中的图片都具有相同size(因为要做stack操作),当一个batch中的图片大小都不同时,可以使用自定义的collate_fn函数,则一个b ...
- C#中Invoke的用法(转)
invoke和begininvoke 区别 一直对invoke和begininvoke的使用和概念比较混乱,这两天看了些资料,对这两个的用法和原理有了些新的认识和理解. 首先说下,invoke和beg ...
- 用漫画的形式来讲解为什么MySQL数据库要用B+树存储索引?
小史是一个应届生,虽然学的是电子专业,但是自己业余时间看了很多互联网与编程方面的书,一心想进BAT互联网公司. 话说两个多月前,小史通过了A厂的一面,两个多月后的今天,小史终于等到了A厂的二面. 简单 ...