左右推拽显示对比图 - jQyery封装 - 附源文件
闲来无事,做了一个模块效果
左右拖拽显示对比图,是用jq封装的
利用鼠标距离左侧(0,0)坐标的横坐标位移来控制绝对定位的left值
再配合背景图fixed属性,来制作视觉差效果
代码如下
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>左右推拽显示对比图</title>
<style>
body {overflow:hidden;background:#000;}* {margin:0;padding:0;}
.wrap {width:1100px;height:610px;border:solid 1px #ddd;margin:0 auto;position:relative;overflow:hidden;background:#fff;}
.box1,.box2 {width:1100px;height:610px;position:absolute;left:0;top:0;}
.box1 {z-index:2;background:url(images/car-01.png) center fixed no-repeat;}
.box2 {z-index:3;background:url(images/car-02.png) center #ddd fixed no-repeat;left:550px;}
.handle {width:42px;height:42px;background:url(images/hand.png) no-repeat;position:absolute;left:529px;z-index:10;top:400px;} .cursor {cursor:url(images/6.ico),auto;}
.nocur {cursor:default;}
</style>
<script src="js/jquery-1.7.2.min.js"></script>
</head> <body id="body">
<div class="wrap">
<div class="box1"></div>
<div class="box2"></div>
<div class="handle"></div>
</div> <script> ;(function($){
$.fn.drag = function(arg,mover){
var _move = false;//先给不让移动
mover = $('.'+mover)
var _x;
var _y; //鼠标离左上角的值
arg = this;
function ab(arg){
arg.mouseover(function(){
$('body').addClass('cursor');
});
arg.mouseout(function(){
$('body').removeClass('cursor');
});
arg.mousedown(function(){
this.style.cursor = 'url(images/5.ico),auto';
});
arg.mouseup(function(){
this.style.cursor = 'url(images/6.ico),auto';
}); arg.click(function(e) {
var e = e || window.event;
//alert('按下鼠标');
}).mousedown(function(e) {
_move = true;
_x = e.pageX - parseInt(arg.css('left'));//获取左上角坐标 _x
});
$(document).mousemove(function(e) {
if(_move == true)
{
var x = e.pageX - _x;// 鼠标当前位置减去(鼠标当前位置,距离元素左上角的距离 s ) 获得现在左上角距离浏览器左上角的新值
if(x > 0 && x < 1100){
arg.css({'left':x});
mover.css({'left':x+21});
}
if (x<=0) {
arg.css({'left':'0px'});
mover.css({'left':'21px'});
}
if (x>1053) {
arg.css({'left':'1058px'});
mover.css({'left':'1079px'});
}
}
}).mouseup(function(e){
_move = false;
}); b = function(){
var i;
arg.animate({left:'1058px'},800);
mover.animate({left:'1079px'},800,function(){
arg.animate({left:'0px'},800);
mover.animate({left:'21px'},800,function(){
arg.animate({'left':'529px'},800);
mover.animate({'left':'550px'},800);
});
});
}
b();
return this;
}
ab(arg);
}
})(jQuery);
$('.handle').drag(this,'box2'); </script>
</body>
</html>
封装的不是很彻底,不过主体效果实现了,可以自己拿着修改一下啊
下面的是缩略图

http://files.cnblogs.com/files/Sinhtml/animation.rar
左右推拽显示对比图 - jQyery封装 - 附源文件的更多相关文章
- android 项目学习随笔十七(ListView、GridView显示组图)
ListView.GridView显示组图,处理机制相同 <?xml version="1.0" encoding="utf-8"?> <Li ...
- Winform中Picture控件图片的拖拽显示
注解:最近做了一个小工具,在Winform中对Picture控件有一个需求,可以通过鼠标从外部拖拽图片到控件的上,释放鼠标,显示图片! 首先你需要对你的整个Fom窗口的AllowDrop设置Ture ...
- excel在一个图表内,显示折线图和柱状图
折线图和柱状图,在同一个图表中拆分显示 一个图,设置主坐标轴 另外一个图,设置次坐标轴 拆分,通过调整纵坐标的最小值和最大值来实现 关于图表的标题,选中图表,选择布局,然后图表 ...
- iOS8自定义推送显示按钮及推送优化
http://www.jianshu.com/p/803bfaae989e iOS8自定义推送显示按钮及推送优化 字数1435 阅读473 评论0 喜欢2 导语 在iOS8中,推送消息不再只是简单地点 ...
- Chart图表整合——面积对比图、扇形图、柱状图
一. chart图表demo网址 网址:http://antv.alipay.com/zh-cn/f2/3.x/demo/index.html 二. 本文主要对面积对比图,扇形图,柱状图三大常见图进行 ...
- Android 使用pl.droidsonroids.gif.GifImageView在安卓中显示动图遇到的问题
在做一款聊天软件,其中聊天界面需要发送表情,而表情都是动图,在安卓中想要显示动图,就要借助第三方框架,我选的是pl.droidsonroids.gif.GifImageView. 使用方法如下:你在g ...
- CS5642-V3与OV5642-FPC通过icamera测试方向的对比图
有朋友会有如此的疑问:CS5642-V3与OV5642-FPC在采集板上通过icamera测试图像方向是一样吗?通过本文您会找到答案 测试:CS5642-V3与OV5642-FPC的管脚在上 以下 ...
- Intel和AMD的CPU性能对比图
Intel和AMD的CPU性能对比图:
- pixijs shader颗粒化显示贴图
pixijs shader颗粒化显示贴图 const app = new PIXI.Application({ transparent: true }); document.body.appendCh ...
随机推荐
- [算法]线段树(IntervalTree)
转载请注明出处:http://www.cnblogs.com/StartoverX/p/4617963.html 线段树是一颗二叉搜索树,线段树将一个区间划分成一些单元区间,每一个区间对应线段树的一个 ...
- C语言+ODBC+SQL 连接
第一步:配置ODBC. ①.在控制面板找到ODBC,或者在控制面板上搜索ODBC.如图: ②.点击ODBC的添加按钮,选择SQL Server,这是会出现创建SQL Server的新数据源的对话框,我 ...
- linux常用命令(5)rmdir命令
rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删除某目录时也必须具有对父目录的写权限.1.命令格 ...
- 推荐IOS开发3个工具:Homebrew、TestFight、Crashlytics-备
1. Homebrew 什么是Homebrew? Homebrew is the easiest and most flexible way to install the UNIX tools App ...
- 检测客户端显示器分辨率、浏览器类型和客户端IP
原文:检测客户端显示器分辨率.浏览器类型和客户端IP 下面的代码实现了检测客户端显示器分辨率.浏览器类型和客户端IP的功能.你可以把客户端信息保存到Session,ViewState等中以便在其它的页 ...
- SignalR Troubleshooting
This document contains the following sections. Calling methods between the client and server silentl ...
- tigerVNC远程桌面,跨内网
tigerVNC的简单使用教程(CentOS的远程桌面连接) 1.环境和软件准备 (1) CentOS 6.5下 [root@localhost ~]$ yum install tigervnc (2 ...
- tarjan缩点
整理了下模板... #include<iostream> #include<cstdio> #include<cmath> #include<algorith ...
- 【转】Thunderbird on Ubuntu 12.04 – 调整邮件列表行间距
原文网址:http://www.xuebuyuan.com/414703.html markz@markz-hp6200:~$ cd .thunderbird/ markz@markz-hp6200: ...
- [转载]STL map中的一些基本函数
来源:(http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html) - C++ map的基本操作和使用_Live_新浪博客 Map是c++的一个标准容器 ...