用 JS 点击左右按钮 使图片切换 - 最精简版-ljx2380000-ChinaUnix博客
2014-12-03 15:39
696 查看
body
{
font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI",Tahoma,Helvetica,Sans-Serif,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLiU,serif;
font-size: 10.5pt;
line-height: 1.5;
}
html, body
{
}
h1 {
font-size:1.5em;
font-weight:bold;
}
h2 {
font-size:1.4em;
font-weight:bold;
}
h3 {
font-size:1.3em;
font-weight:bold;
}
h4 {
font-size:1.2em;
font-weight:bold;
}
h5 {
font-size:1.1em;
font-weight:bold;
}
h6 {
font-size:1.0em;
font-weight:bold;
}
img {
border:0;
max-width: 100%;
}
blockquote {
margin-top:0px;
margin-bottom:0px;
}
table {
border-collapse:collapse;
border:1px solid #bbbbbb;
}
td {
border-collapse:collapse;
border:1px solid #bbbbbb;
}
用 JS 点击左右按钮 使图片切换 - 最精简版-ljx2380000-ChinaUnix博客
![](http://images.cnitblog.com/blog/479631/201412/031538459511396.png)
代码部分:
点击(此处)折叠或打开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>实用的图片切换</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
<!--<script type="text/javascript" src="jquery_change.js"></script>-->
<style type="text/css">
body,ul,li { padding:0; margin:0}
ul,li { list-style:none}
.img-scroll { position:relative; margin:20px auto; width:440px;}
.img-scroll .prev,.img-scroll .next { position:absolute; display:block; width:50px; height:100px; background-color:#000;
top:0; color:#FFF; text-align:center; line-height:100px}
.img-scroll .prev { left:0;cursor:pointer;}
.img-scroll .next { right:0;cursor:pointer;}
.img-list { position:relative; width:320px; height:100px; margin-left:60px; overflow:hidden}
.img-list ul { width:9999px;}
.img-list li { float:left; display:inline; width:100px; margin-right:10px; height:100px; background-color:#BDBDDF; text-align:center; line-height:100px;}
</style>
</head>
<body>
<div class="img-scroll">
<span class="prev">prev</span>
<span class="next">next</span>
<div class="img-list">
<ul>
<li><img style="width:100px;height:100px;" src="./img/cat.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/katong.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/meinv.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/mm.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/慢慢.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/美食杰-糖糖.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/未命名44.jpg"></li>
</ul>
</div>
</div>
<script type="text/javascript">
function DY_scroll(wraper,prev,next,img,speed,or)
{
var wraper = $(wraper);
var prev = $(prev);
var next = $(next);
var img = $(img).find('ul');
var w = img.find('li').outerWidth(true);
var s = speed;
next.click(function()
{
img.animate({'margin-left':-w},function()
{
img.find('li').eq(0).appendTo(img);
img.css({'margin-left':0});
});
});
prev.click(function()
{
img.find('li:last').prependTo(img);
img.css({'margin-left':-w});
img.animate({'margin-left':0});
});
if (or == true)
{
ad = setInterval(function() { next.click();},s*1000);
wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);});
}
}
DY_scroll('.img-scroll','.prev','.next','.img-list',3,false);// true为自动播放,不加此参数或false就默认不自动
</script>
</body>
</html>
来自为知笔记(Wiz)
{
font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI",Tahoma,Helvetica,Sans-Serif,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLiU,serif;
font-size: 10.5pt;
line-height: 1.5;
}
html, body
{
}
h1 {
font-size:1.5em;
font-weight:bold;
}
h2 {
font-size:1.4em;
font-weight:bold;
}
h3 {
font-size:1.3em;
font-weight:bold;
}
h4 {
font-size:1.2em;
font-weight:bold;
}
h5 {
font-size:1.1em;
font-weight:bold;
}
h6 {
font-size:1.0em;
font-weight:bold;
}
img {
border:0;
max-width: 100%;
}
blockquote {
margin-top:0px;
margin-bottom:0px;
}
table {
border-collapse:collapse;
border:1px solid #bbbbbb;
}
td {
border-collapse:collapse;
border:1px solid #bbbbbb;
}
用 JS 点击左右按钮 使图片切换 - 最精简版-ljx2380000-ChinaUnix博客
![](http://images.cnitblog.com/blog/479631/201412/031538459511396.png)
代码部分:
点击(此处)折叠或打开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>实用的图片切换</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
<!--<script type="text/javascript" src="jquery_change.js"></script>-->
<style type="text/css">
body,ul,li { padding:0; margin:0}
ul,li { list-style:none}
.img-scroll { position:relative; margin:20px auto; width:440px;}
.img-scroll .prev,.img-scroll .next { position:absolute; display:block; width:50px; height:100px; background-color:#000;
top:0; color:#FFF; text-align:center; line-height:100px}
.img-scroll .prev { left:0;cursor:pointer;}
.img-scroll .next { right:0;cursor:pointer;}
.img-list { position:relative; width:320px; height:100px; margin-left:60px; overflow:hidden}
.img-list ul { width:9999px;}
.img-list li { float:left; display:inline; width:100px; margin-right:10px; height:100px; background-color:#BDBDDF; text-align:center; line-height:100px;}
</style>
</head>
<body>
<div class="img-scroll">
<span class="prev">prev</span>
<span class="next">next</span>
<div class="img-list">
<ul>
<li><img style="width:100px;height:100px;" src="./img/cat.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/katong.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/meinv.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/mm.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/慢慢.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/美食杰-糖糖.jpg"></li>
<li><img style="width:100px;height:100px;" src="./img/未命名44.jpg"></li>
</ul>
</div>
</div>
<script type="text/javascript">
function DY_scroll(wraper,prev,next,img,speed,or)
{
var wraper = $(wraper);
var prev = $(prev);
var next = $(next);
var img = $(img).find('ul');
var w = img.find('li').outerWidth(true);
var s = speed;
next.click(function()
{
img.animate({'margin-left':-w},function()
{
img.find('li').eq(0).appendTo(img);
img.css({'margin-left':0});
});
});
prev.click(function()
{
img.find('li:last').prependTo(img);
img.css({'margin-left':-w});
img.animate({'margin-left':0});
});
if (or == true)
{
ad = setInterval(function() { next.click();},s*1000);
wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);});
}
}
DY_scroll('.img-scroll','.prev','.next','.img-list',3,false);// true为自动播放,不加此参数或false就默认不自动
</script>
</body>
</html>
来自为知笔记(Wiz)
相关文章推荐
- 用 JS 点击左右按钮 使图片切换 - 最精简版
- 用 JS 点击左右按钮 使图片切换 - 最精简版
- js图片轮播可控制是否循环轮播,点击左右按钮切换
- js鼠标点击按钮切换图片-图片自动切换-点击左右按钮切换特效代码
- js鼠标点击按钮切换图片-图片自动切换-点击左右按钮切换特效代码
- 用 JS 点击左右按钮 使图片切换
- JS实现点击按钮图片左右切换、点击图片按钮出现下拉菜单
- JQuery------实现点击左右按钮,切换图片功能
- Js_图片切换左右点击
- 原生JS编写图片切换效果和点击按钮的样式变化
- js实现点击左右按钮轮播图片效果实例
- js实现点击左右按钮轮播图片效果实例
- js各种图片轮播滑动插件 上下,左右缩略图按钮点击图
- 鼠标点击按钮图片切换+自动切换+左右按钮点击切换效果
- 利用JS实现点击按钮后图片自动切换
- 利用JS实现点击按钮后图片自动切换的简单方法
- jquery——左右按钮点击切换一组图片功能
- 基于jquery实现左右按钮点击的图片切换效果
- 基于jquery实现左右按钮点击的图片切换效果
- JS+CSS带数字和左右按钮可控制切换的图片幻灯