Javascript 图片左右滑动与切换
Html代码 :
<div class="v_out v_out_p">
<div class="prev">
<a href="javascript:void(0)"></a>
</div>
<div class="v_show">
<div class="v_cont">
<ul>
<li index="0" style="background: #f00">[第1讲]</li>
<li index="1" style="background: #ff0">[第2讲]</li>
<li index="2" style="background: #f0f">[第3讲]</li>
<li index="3" style="background: #999">[第4讲]</li>
<li index="4" style="background: #666">[第5讲]</li>
</ul>
</div>
</div>
<div class="next">
<a href="javascript:void(0)"></a>
</div>
<ul class="circle">
<li class="circle-cur">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
<script type="text/javascript">
$(function () {
/*======next======*/
$(".next a").click(function () { nextscroll() });
function nextscroll() {
var vcon = $(".v_cont ");
var offset = ($(".v_cont li").width()) * -1;
vcon.stop().animate({ left: offset }, "slow", function () {
var firstItem = $(".v_cont ul li").first();
vcon.find("ul").append(firstItem);
$(this).css("left", "0px");
circle()
});
};
function circle() {
var currentItem = $(".v_cont ul li").first();
var currentIndex = currentItem.attr("index");
$(".circle li").removeClass("circle-cur");
$(".circle li").eq(currentIndex).addClass("circle-cur");
}
//setInterval(nextscroll,2000)
/*======prev======*/
$(".prev a").click(function () {
var vcon = $(".v_cont ");
var offset = ($(".v_cont li").width() * -1);
var lastItem = $(".v_cont ul li").last();
vcon.find("ul").prepend(lastItem);
vcon.css("left", offset);
vcon.animate({ left: "0px" }, "slow", function () {
circle()
})
});
/*======btn====circle======*/
var animateEnd = 1;
$(".circle li").click(function () {
if (animateEnd == 0) { return; }
$(this).addClass("circle-cur").siblings().removeClass("circle-cur");
var nextindex = $(this).index();
var currentindex = $(".v_cont li").first().attr("index");
var curr = $(".v_cont li").first().clone();
if (nextindex > currentindex) {
for (var i = 0; i < nextindex - currentindex; i++) {
var firstItem = $(".v_cont li").first();
$(".v_cont ul").append(firstItem);
}
$(".v_cont ul").prepend(curr);
var offset = ($(".v_cont li").width()) * -1;
if (animateEnd == 1) {
animateEnd = 0;
$(".v_cont").stop().animate({ left: offset }, "slow", function () {
$(".v_cont ul li").first().remove();
$(".v_cont").css("left", "0px");
animateEnd = 1;
});
}
} else {
var curt = $(".v_cont li").last().clone();
for (var i = 0; i < currentindex - nextindex; i++) {
var lastItem = $(".v_cont li").last();
$(".v_cont ul").prepend(lastItem);
}
$(".v_cont ul").append(curt);
var offset = ($(".v_cont li").width()) * -1;
$(".v_cont").css("left", offset);
if (animateEnd == 1) {
animateEnd = 0;
$(".v_cont").stop().animate({ left: "0px" }, "slow", function () {
$(".v_cont ul li").last().remove();
animateEnd = 1;
});
}
}
});
})
</script>
============================================================================================================
css代码:
*
{
margin: 0px;
padding: 0px;
list-style-type: none;
}
.v_out
{
width: 748px;
margin: 20px auto;
overflow: hidden;
}
.v_show
{
width: 665px;
overflow: hidden;
position: relative;
height: 280px;
float: left;
}
.v_cont
{
width: 6650px;
position: absolute;
left: 0px;
top: 0px;
}
.v_cont ul
{
float: left;
text-align: center;
line-height: 50px;
}
.v_cont ul li
{
width: 665px;
height: 250px;
background: #f8f8f8;
float: left;
margin-top: 3px;
}
/*---圆圈---*/
.v_out_p
{
position: relative;
overflow: visible;
}
.circle
{
position: absolute;
left: 40px;
top: 290px;
}
.circle li
{
width: 120px;
height: 60px;
float: left;
margin-right: 10px;
background: #ccc;
}
.circle .circle-cur
{
background: #f00;
}
/*---切换---*/
.prev, .next
{
float: left;
padding: 105px 9px 0;
}
.prev a
{
background: #f00;
}
.prev .ico_1
{
background: url(input_a.gif) no-repeat 0 -3757px;
}
.next a
{
background: #f00;
}
.next .ico_2
{
background: url(input_a.gif) no-repeat right -3757px;
}
.prev, .prev a, .next, .next a
{
width: 21px;
height: 28px;
display: block;
}
Javascript 图片左右滑动与切换的更多相关文章
- 基于jQuery图片遮罩滑动文字切换特效
基于jQuery图片遮罩滑动文字切换特效.这是一款jquery hover鼠标滑动选项卡切换透明背景遮罩文字显示特效.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div ...
- javascript图片切换
JavaScript 图片滑动切换效果 作者:cloudgamer 时间: 2009-09-25 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript 图片滑动切换效果 [1] 第 2 页 ...
- 高仿优酷Android客户端图片左右滑动(自动切换)
本例是用ViewPager去做的实现,支持自动滑动和手动滑动,不仅优酷网,实际上有很多商城和门户网站都有类似的实现: 具体思路: 1. 工程中需要添加android-support-v4.jar,才能 ...
- Javascript图片预加载详解
预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...
- 仿优酷Android客户端图片左右滑动(自动滑动)
最终效果: 页面布局main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayou ...
- 图片轮播(左右切换)--JS原生和jQuery实现
图片轮播(左右切换)--js原生和jquery实现 左右切换的做法基本步骤跟 上一篇文章 淡入淡出 类似,只不过修改了一些特定的部分 (1)首先是页面的结构部分 对于我这种左右切换式 1.首先是个外 ...
- javascript - 图片的幻灯片效果
javascript 代码: <script type="text/javascript"> function select_play() { var select_p ...
- Javascript图片预加载详解 分类: JavaScript HTML+CSS 2015-05-29 11:01 768人阅读 评论(0) 收藏
预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...
- JavaScript banner轮播 左右切换 圆点点击切换
1.效果如下图: 2.源码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
随机推荐
- hdu 4252 A Famous City
题意:一张相片上的很多建筑相互遮住了,根据高低不同就在相片上把一座高楼的可见部分作为一个矩形,并用数字描述其高度,若一张相片上的两个建筑群中间有空地,高度则为0;求最少有多少个建筑; 分析: 输入的0 ...
- xampp改到phpmyadmin的root密碼無法登錄
open /Applications/XAMPP/xamppfiles/phpmyadmin/config.inc.php $cfg['Servers'][$i]['auth_type'] = 'co ...
- zboot/xtract.c
/* * linux/zBoot/xtract.c * * Copyright (C) 1993 Hannu Savolainen * * Extracts the system imag ...
- 【渗透测试学习平台】 web for pentester -3.XSS
Example 1 http://192.168.91.139/xss/example1.php?name=hacker<script>alert('xss')</script> ...
- codeforces 192e
link: http://codeforces.com/contest/330/problem/E /* ID: zypz4571 LANG: C++ TASK: 192e.cpp */ #inclu ...
- Codeforces Round #123 (Div. 2)
A. Let's Watch Football 记时间为\(t\), 则\(bt+(b-a)c>=0\),可得\[t \ge \frac{c(a-b)}{b}\] B. After Traini ...
- spark新能优化之广播共享数据
如果你的算子函数中,使用到了特别大的数据,那么,这个时候,推荐将该数据进行广播.这样的话,就不至于将一个大数据拷贝到每一个task上去.而是给每个节点拷贝一份,然后节点上的task共享该数据. 这样的 ...
- poj2912 带权并查集
题意:多个人玩石头剪刀布,每个人提前选定了自己出哪个手势,而其中有一种特殊的人他可以随意出什么手势,问是否能够从给出的一系列石头剪刀布游戏中判断出哪个是特殊的,可以从第几局游戏中判断出来. 首先按照食 ...
- 【NOIP2007】矩阵取数
因为傻逼写错高精度搞了一下午浪费好多时间,好想哭qaq 原题: 帅帅经常更同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij据为非负整数.游戏规则如下: 1. 每次取数时须从每 ...
- NetStatusEvent info对象的状态或错误情况的属性
代码属性 级别属性 意义 "NetStream.Buffer.Empty" "status" 数据的接收速度不足以填充缓冲区.数据流将在缓冲区重新填充前中 ...