JS实现两张图片卷轴的切换效果
2011-06-13 15:24
856 查看
效果参见:
http://weitwo.com/home.htm
引入jQuery后,
再引入如下JS:
$(document).ready(function () {
var slidePicture = new sliderPicture();
slidePicture.containerId = 'container';
slidePicture.frontId = 'front';
slidePicture.minFrontWidth = 100;
slidePicture.load();
});
function sliderPicture() {
this.containerId = '';
this.frontId = '';
this.minFrontWidth = 200;
this.load = function () {
var container = $('#' + this.containerId);
var front = $('#' + this.frontId);
var minWith = this.minFrontWidth;
container.mousemove(function (e) {
var offsetLeft = container.prop("offsetLeft");
var parentWidth = container.prop("clientWidth");
var left = e.clientX - offsetLeft;
var width = parentWidth - left;
if (width >= minWith) {
front.width(width);
}
});
}
}
添加如下样式:
#container
{
background:url('http://photocdn.sohu.com/20110527/Img308750491.jpg');
width:90%;
height:200px;
margin:0px auto;
}
#front
{
float:right;
background:url('http://news3.xinhuanet.com/auto/2005-07/06/xinsrc_3520702061714562873521.jpg');
background-position:right;
width:30%;
height:100%;
}
#splitter
{
background:#000000;
height:100%;
float:left;
width:5px;
}
添加如下HTML:
<div id="container">
<div id="front">
<span id="splitter"></span>
</div>
</div>
即可实现图片卷轴的效果。
http://weitwo.com/home.htm
引入jQuery后,
再引入如下JS:
$(document).ready(function () {
var slidePicture = new sliderPicture();
slidePicture.containerId = 'container';
slidePicture.frontId = 'front';
slidePicture.minFrontWidth = 100;
slidePicture.load();
});
function sliderPicture() {
this.containerId = '';
this.frontId = '';
this.minFrontWidth = 200;
this.load = function () {
var container = $('#' + this.containerId);
var front = $('#' + this.frontId);
var minWith = this.minFrontWidth;
container.mousemove(function (e) {
var offsetLeft = container.prop("offsetLeft");
var parentWidth = container.prop("clientWidth");
var left = e.clientX - offsetLeft;
var width = parentWidth - left;
if (width >= minWith) {
front.width(width);
}
});
}
}
添加如下样式:
#container
{
background:url('http://photocdn.sohu.com/20110527/Img308750491.jpg');
width:90%;
height:200px;
margin:0px auto;
}
#front
{
float:right;
background:url('http://news3.xinhuanet.com/auto/2005-07/06/xinsrc_3520702061714562873521.jpg');
background-position:right;
width:30%;
height:100%;
}
#splitter
{
background:#000000;
height:100%;
float:left;
width:5px;
}
添加如下HTML:
<div id="container">
<div id="front">
<span id="splitter"></span>
</div>
</div>
即可实现图片卷轴的效果。
相关文章推荐
- 原生JS实现隐藏显示图片 JS实现点击切换图片效果
- js实现同一页面可多次调用的图片幻灯切换效果
- 原生js实现图片层叠轮播切换效果
- js实现百度联盟中一款不错的图片切换效果完整实例
- JS实现的文字与图片定时切换效果代码
- js实现支持手机滑动切换的轮播图片效果实例
- JS实现FLASH幻灯片图片切换效果的方法
- js组件SlotMachine实现图片切换效果制作抽奖系统
- JS实现FLASH幻灯片图片切换效果的方法
- JS实现的文字与图片定时切换效果代码
- JS原生实现图片轮播切换效果
- js实现图片翻转切换效果
- JS实现图片高斯模糊切换效果的焦点图实例
- Js实现类似图片相册左右切换效果
- js实现图片淡入淡出切换简易效果
- js实现索引图片切换效果
- js实现图片自动切换效果
- Js实现类似图片相册左右切换效果
- 自定义属性之图片切换实例——初始化、实现切换效果——JS学习笔记2015-5-29(第42天)
- js实现图片从左往右渐变切换效果的方法