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 ...
随机推荐
- 解决织梦标签artlist不能调用副栏目的问题?
本文转自:http://www.xinshou5.com/a/127.html 织梦列表页中不支持artlist这个标签,这样怎么调用副栏目? 想要在列表页调用副栏目,但是列表页不支持artlist这 ...
- JAVA 遍历文件夹下的所有文件
JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...
- Apache与Nginx服务器对比
apache NginX 占用资源和内存 多 轻量级,同样起Web服务,占内存和资源更少 阻塞型 抗并发,异步非阻塞的,高并发下,可保持低资源低消耗低性能 可用的模块超多 可自定义模块,编 ...
- c#实现数据的左补右补功能
/// <summary> /// 左補右補功能 /// </summary> /// <param name="st ...
- 灰度图像的自动阈值分割(Otsu 法)(转载)
灰度图像的自动阈值分割(Otsu 法) 机器视觉领域许多算法都要求先对图像进行二值化.这种二值化操作阈值的选取非常重要.阈值选取的不合适,可能得到的结果就毫无用处.今天就来讲讲一种自动计算阈值的方法. ...
- (转)Hadoop数据类型
来源: http://www.cnblogs.com/anny-1980/articles/2608097.html BooleanWritable:标准布尔型数值 ByteWritable:单字节数 ...
- leetcode 115 Distinct Subsequences ----- java
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- 使用密钥验证方式登录linux系统
1.使用PuTTY工具PuTTYgen生成密钥对,打开PuTTYgen,点击Generate生成公钥(生成过程动动鼠标会提升进度哦). 2.将公钥(蓝色的是私钥)放到服务器上去: -在/root目录下 ...
- [转]GIT PUSH Error 403的解决方法
http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-reques ...
- ob_start()失效与phpunit的非正常结束
在ob_clean();或ob_get_clean()之前有return或致命错误,从而结束了程序,会导致ob_start失效, 这和phpunit的非正常结束