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 ...
随机推荐
- 文件转换神器Pandoc使用
最近记录笔记,改用Markdown格式.但有时需要分享下笔记,对于不懂markdown格式的同学来说阅读感觉不是那么友好.因此就一直在寻找一款文件转换的软件,之前因为用markdownpad来编写,可 ...
- iOS学习笔记---oc语言第七天
类的扩展 NSDate是Cocoa中用于处理日期和时间的基础类,封装了某一给定的时刻,具体的日期 时间和时区 使用+date方法获取当前日期和时间 NSDate *date = [NSDate dat ...
- ZOJ 1243 URLs
/*In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the ...
- 经典 socket通讯 -- 已验证
[tcp通信] 来源:不详: client: package com.defonds.socket.begin; import java.io.BufferedReader; import java. ...
- tomcat 启动时内存溢出
在tomcat_home/bin目录下找到catalina.bat,用文本编辑器打开,加上下面一行: set JAVA_OPTS= -Xms1024M -Xmx1024M -XX:PermSize=2 ...
- squid代理服务器搭建及配置
系统环境:CentOS release 6.5 (Final)(最小化安装) 一.安装squid # yum -y install squid 二.编辑配置文件(正向代理) # vim /etc/sq ...
- HDU-5781 ATM Mechine(概率DP)
题目大意:某个未知整数x等概率的分布在[0,k]中.每次你都可以从这个整数中减去一个任意整数y,如果x>=y,那么x=x-y,操作次数累计加1:否则,将会受到一次错误提示.当错误提示超过w次,将 ...
- caffe:编译时提示:unsupported GNU version! gcc versions later than 4.9 are not supported!
NVCC src/caffe/solvers/adam_solver.cuIn file included from /usr/local/cuda/include/cuda_runtime.h:76 ...
- about java techelogly
https://docs.oracle.com/javase/tutorial/getStarted/intro/definition.html Differences between Java EE ...
- docker镜像、容器
第一部分:Docker镜像的基本知识 1.1 什么是Docker镜像 从整体的角度来讲,一个完整的Docker镜像可以支撑一个Docker容器的运行,在 Docker容器运行过程中主要提供文件系统视角 ...