导航:首页 > 编程语言 > js可控的左右滚动图片

js可控的左右滚动图片

发布时间:2021-02-23 17:13:28

js图片左右滚动

<div style="height:200px; width:1002px;">
<div class='l' style="float:left; height:200px; width:50px;"><a href="#">鼠标指上后向左移动,离开后停止</a></div>
<div class='nn' style="float:left; height:200px; width:902px; overflow:hidden;">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="s1">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
<td><img src="images/zy_19.jpg" width="176" height="102" /></td>
</tr>
</table>
</td>
<td class="s2"></td>
</tr>
</table>
</div>
<div class='r' style="float:left; height:200px; width:50px;"><a href="#">鼠标指上后向右移动,离开后停止</a></div>
</div>

<script>
function roll(obj,s1,s2,l,r){
var play;
s2.html(s1.html());
function gd(f){
if(f=='r'){
if(obj.scrollLeft()>0){
obj.scrollLeft(obj.scrollLeft()-1);
}else{
obj.scrollLeft(s1.width());
}
}else{
if(obj.scrollLeft()<=s1.width()){
obj.scrollLeft(obj.scrollLeft()+1);
}else{
obj.scrollLeft(0);
}
}
}
l.hover(function(){play=setInterval(gd,20)},function(){clearInterval(play)});
r.hover(function(){play=setInterval(function(){gd("r")},20)},function(){clearInterval(play)});
}

$roll($('.nn'),$('.s1'),$('.s2'),$('.l'),$('.r'));
</script>

头部调用jquery 去www.jquery.com下载

修改完毕 试试吧

② js实现点击按钮图片左右滚动,不要自动滚动的。谢谢各位了!

文章由贝奇动漫网搜集整理
//XHTML代码

<div class="rollBox">
<img onmousedown="ISL_GoDown()" onmouseup="ISL_StopDown()" onmouseout="ISL_StopDown()" class="img1" src="../images/life/shqm_left_pic.gif"

width="12" height="31" />
<div class="Cont" id="ISL_Cont">
<div class="ScrCont">
<div id="List1">

<!-- 图片列表 begin -->

<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>

<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>
<div class="pic">
<a href="#" target="_blank"><img src="../images/life/show_1.jpg" width="130" height="95" /></a>
<a href="#" target="_blank">从巴黎旧公寓学家装点</a>
</div>

<!-- 图片列表 end -->

</div>
<div id="List2"></div>
</div>
</div>
<img onmousedown="ISL_GoUp()" onmouseup="ISL_StopUp()" onmouseout="ISL_StopUp()" class="img2" src="../images/life/shqm_right_pic.gif"

width="12" height="31" />
</div>

//CSS代码

.rollBox{width:620px;overflow:hidden;margin:0 auto;}
.rollBox .Cont{width:620px;overflow:hidden;margin:0 auto;padding-top:20px;}
.rollBox .ScrCont{width:10000000px;}
.rollBox .Cont .pic{width:130px;float:left;text-align:center;padding-right:20px;}
*+html .rollBox .Cont .pic{width:130px;float:left;text-align:center;padding-right:30px;}
.rollBox .Cont .pic img{padding:4px;background:#fff;border:1px solid #ccc;display:block;margin:0 auto;}
.rollBox .Cont .pic p{line-height:26px;color:#505050;}
.rollBox .Cont a:link,.rollBox .Cont a:visited{color:#626466;text-decoration:none;}
.rollBox .Cont a:hover{color:#f00;text-decoration:underline;}
.rollBox #List1,.rollBox #List2{float:left;}

//JS代码

<script language="javascript" type="text/javascript">
<!--//--><![CDATA[//><!--
//图片滚动列表 mengjia 070816
var Speed = 10; //速度(毫秒)
var Space = 10; //每次移动(px)
var PageWidth = 160; //翻页宽度
var fill = 0; //整体移位
var MoveLock = false;
var MoveTimeObj;
var Comp = 0;
var AutoPlayObj = null;
GetObj("List2").innerHTML = GetObj("List1").innerHTML;
GetObj('ISL_Cont').scrollLeft = fill;
GetObj("ISL_Cont").onmouseover = function(){clearInterval(AutoPlayObj);}
GetObj("ISL_Cont").onmouseout = function(){AutoPlay();}
AutoPlay();
function GetObj(objName){if(document.getElementByIdx){return eval_r('document.getElementByIdx("'+objName+'")')}else{return eval

('document.all.'+objName)}}
function AutoPlay(){ //自动滚动
clearInterval(AutoPlayObj);
AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',5000); //间隔时间
}
function ISL_GoUp(){ //上翻开始
if(MoveLock) return;
clearInterval(AutoPlayObj);
MoveLock = true;
MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
}
function ISL_StopUp(){ //上翻停止
clearInterval(MoveTimeObj);
if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0){
Comp = fill - (GetObj('ISL_Cont').scrollLeft % PageWidth);
CompScr();
}else{
MoveLock = false;
}
AutoPlay();
}
function ISL_ScrUp(){ //上翻动作
if(GetObj('ISL_Cont').scrollLeft <= 0){GetObj('ISL_Cont').scrollLeft = GetObj

('ISL_Cont').scrollLeft + GetObj('List1').offsetWidth}
GetObj('ISL_Cont').scrollLeft -= Space ;
}
function ISL_GoDown(){ //下翻
clearInterval(MoveTimeObj);
if(MoveLock) return;
clearInterval(AutoPlayObj);
MoveLock = true;
ISL_ScrDown();
MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
}
function ISL_StopDown(){ //下翻停止
clearInterval(MoveTimeObj);
if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0 ){
Comp = PageWidth - GetObj('ISL_Cont').scrollLeft % PageWidth + fill;
CompScr();
}else{
MoveLock = false;
}
AutoPlay();
}
function ISL_ScrDown(){ //下翻动作
if(GetObj('ISL_Cont').scrollLeft >= GetObj('List1').scrollWidth){GetObj('ISL_Cont').scrollLeft =

GetObj('ISL_Cont').scrollLeft - GetObj('List1').scrollWidth;}
GetObj('ISL_Cont').scrollLeft += Space ;
}
function CompScr(){
var num;
if(Comp == 0){MoveLock = false;return;}
if(Comp < 0){ //上翻
if(Comp < -Space){
Comp += Space;
num = Space;
}else{
num = -Comp;
Comp = 0;
}
GetObj('ISL_Cont').scrollLeft -= num;
setTimeout('CompScr()',Speed);
}else{ //下翻
if(Comp > Space){
Comp -= Space;
num = Space;
}else{
num = Comp;
Comp = 0;
}
GetObj('ISL_Cont').scrollLeft += num;
setTimeout('CompScr()',Speed);
}
}
//--><!]]>
</script>

PS:注意CSS里层宽度的设置

③ js写图片滚动 实现自己可以左右调动

//我项目里的一个例子。
//==============================================
<!DOCTYPEhtml>
<html>
<metacharset="utf-8"/>
<title></title>
t>
<scripttype="text/javascript"src="js/slider.js"></script>
<scripttype="text/javascript"src="js/jquery-1.9.1.min.js"></script>
<body>
<divid="banner_tabs"class="flexslider">
<ulclass="slides">
<li>
<a>
<imgwidth="1920"height="600"style="background:url(images/banner_1.jpg)no-repeatcenter;"src="images/alpha.png">
</a>
</li>
<li>
<a>
<imgwidth="1920"height="600"style="background:url(images/banner_2.jpg)no-repeatcenter;"src="images/alpha.png">
</a>
</li>
<li>
<a>
<imgwidth="1920"height="600"style="background:url(images/banner_3.jpg)no-repeatcenter;"src="images/alpha.png">
</a>
</li>
</ul>
<ulclass="flex-direction-nav">
<li><aclass="flex-prev"href="javascript:;">Previous</a></li>
<li><aclass="flex-next"href="javascript:;">Next</a></li>
</ul>
<olid="bannerCtrl"class="flex-control-navflex-control-paging">
<liclass="active"><a>1</a></li>
<liclass=""><a>2</a></li>
<liclass=""><a>3</a></li>
</ol>
</div>
<scriptsrc="js/jquery.js"></script>
<scripttype="text/javascript">
$(function(){
varbannerSlider=newSlider($('#banner_tabs'),{
time:5000,
delay:400,
event:'hover',
auto:true,
mode:'fade',
controller:$('#bannerCtrl'),
activeControllerCls:'active'
});
$('#banner_tabs.flex-prev').click(function(){
bannerSlider.prev()
});
$('#banner_tabs.flex-next').click(function(){
bannerSlider.next()
});
})
</script>
</body>
</html>
//==========================================
//slider,jq自己下载,相信不用我教。
//顺便可以看看教程,对这些有点了解。

④ 求一个JS特效,图片左右滚动 点击左右的箭头可以滚动一条的,

<!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>
<title>无标题页</title>
<script type="text/javascript" src="http://www.suqian.cm/js/ScrollPic.js"></script>
</head>
<body>
<style type="text/css">
.pic_top div{float:left}
.pic_yi{height:80px; width:80px;padding:20px}
</style>
<div class="pic_top">
<div class="pic_left" id="LeftArr" style="height:100px; width:200px;">鼠标点击向左(left)滚动</div>

<div class="pic_center" id="divAcrollPic1" style=" height:100px; width:400px; overflow:hidden; ">
<div class="pic_yi">图片</div>
<div class="pic_yi">图片</div>
<div class="pic_yi">图片</div>
<div class="pic_yi">图片</div>
</div>

<div class="pic_right" id="RightArr" style="height:100px; width:200px;">鼠标点击向右(right)滚动</div>
</div>
<script type="text/javascript">
// 左右点击滚动开始
var scrollPic1 = new ScrollPic();
scrollPic1.scrollContId = "divAcrollPic1"; //内容容器ID
scrollPic1.arrLeftId = "LeftArr";//左箭头ID
scrollPic1.arrRightId = "RightArr"; //右箭头ID

scrollPic1.frameWidth = 400;//显示框宽度
scrollPic1.pageWidth = 100; //翻页宽度

scrollPic1.speed = 10; //移动速度(单位毫秒,越小越快)
scrollPic1.space = 10; //每次移动像素(单位px,越大越快)
scrollPic1.autoPlay = false; //自动播放
scrollPic1.autoPlayTime = 3; //自动播放间隔时间(秒)

scrollPic1.initialize(); //初始化
// 左右点击滚动结束
</script>
</body>
</html>

⑤ js实现图片左右滚动

根据楼上做了点修改,这是用jquery,所以一定要链接jquery库。
<html>
<head>
<title></title>
<styletype="text/css">
body,ul,li{list-style:noneoutsidenone;padding:0;margin:0;}
#picScroll{width:350px;overflow:hidden;}
ul{width:1000%;}
ulli{float:left;}
liimg{width:100px;height:100px;}
</style>
<scripttype="text/javascript"src="jquery-1.4.2.min.js"></script>
</head>
<body>

<divid="picScroll">
<ul>
<li>
<a><imgsrc="../pic/1.jpg"/></a>
<a><imgsrc="../pic/2.jpg"/></a>
<a><imgsrc="../pic/3.jpg"/></a>
<a><imgsrc="../pic/4.jpg"/></a>
<a><imgsrc="../pic/5.jpg"/></a>
</li>
<li></li>
</ul>
</div>
<scripttype="text/javascript">
vartarget=$('#picScroll');//其实标准的写法是var$target=$('#picScroll');
varleft=0;
varspeed=30;

varli=$('#picScrollulli');
li.eq(1).html(li.eq(0).html());//复制第一个li节点内容,赋值给第二个li目的是为了实现无限循环滚动
functionMarqeen(){
if(li[0].offsetWidth<=left){
left-=li[0].offsetWidth;
}
else{
left++;
}
target.scrollLeft(left);
}
$(function(){
varmarQueen=window.setInterval(Marqeen,speed);
target.mouseover(function(){
clearInterval(marQueen);
});
target.mouseout(function(){
marQueen=window.setInterval(Marqeen,speed);
});
});
</script>
</body>
</html>


下面是用 js 写的,不用连接jquery库了,可以对比一下上面的jquery代码

<scripttype="text/javascript">
vartarget=document.getElementById('picScroll');
varleft=0;
varspeed=30;

varLI=target.getElementsByTagName('li');
LI[1].innerHTML=LI[0].innerHTML;
functionMarqeen(){

if(LI[0].offsetWidth<=left){
left-=LI[0].offsetWidth;
}
else{
left++;
}
target.scrollLeft=left;
}

varmarQueen=window.setInterval(Marqeen,speed);
target.mouseover=function(){
clearInterval(marQueen);
};
target.mouseout=function(){
marQueen=window.setInterval(Marqeen,speed);};
</script>

⑥ 图片左右自动滚动js代码

这是一个用的非常多的左右滚动的代码。http://www.lanrentuku.com/js/jiaodiantu-813.html
还有其他的是:http://www.jb51.net/article/14422.htm
这个各内个滚动都有了。容

⑦ 求一个JS图片左右滚动加按钮的代码!!!!十分感谢!!!!!!

http://www.csrcode.cn/html/txdm/
可以在这里找哦内。容

⑧ html 图片左右自动滚动js实现效果

类似这个效果的网上很多的啦,弄个改改就行了。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JS平滑图片滚动</title>
<SCRIPT language=JavaScript type=text/JavaScript>
var sh;
var marquees;
marqueesWidth=610;
var speed=20,preLeft=0,stopscroll=false,flag=true;
function scrollLeft(){
preLeft=marquees.scrollLeft;
marquees.scrollLeft+=3;
if(preLeft>=marquees.scrollLeft){
Right();
}
}
function scrollRight(){
preLeft=marquees.scrollLeft;
marquees.scrollLeft-=3;
if(preLeft<=marquees.scrollLeft){
Left();
}
}
function Left(){
flag=true;
clearInterval( sh );
sh = setInterval("scrollLeft()",speed);
}
function Right(){
flag=false;
clearInterval( sh );
sh = setInterval("scrollRight()",speed);
}

function normal(){
clearInterval( sh );
speed=20;
if(flag)Left();
else Right();
}
function plusSpeed(){
clearInterval( sh );
speed=10;
if(flag)Left();
else Right();
}
function init(){
marquees=document.getElementById("marquees1");
with(marquees){
style.width=marqueesWidth+"px";
style.overflowX="hidden";
style.overflowY="visible";
}
Left();
}
</SCRIPT>
</head>
<body onload="init()">
<TABLE cellSpacing=1 width=660 align=center border=0>
<TR bgColor=#f8f8f8>
<TD align=middle width=25><img
src="http://www.codefans.net/jscss/demoimg/200905/left.gif" border=0 onmouseout=normal() onmouseover=plusSpeed() style="CURSOR: pointer" /></TD>
<TD>
<DIV id="marquees1">
<TABLE border=0><TR>

<TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s9.jpg' border=0 /></td>
</tr><tr><td><div align="center">第1期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s1.jpg' border=0 /></td>
</tr><tr><td><div align="center">第2期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s2.jpg' border=0 /></td>
</tr><tr><td><div align="center">第3期 </div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s3.jpg' border=0 /></td>
</tr><tr><td><div align="center">第4期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s4.jpg' border=0 /></td>
</tr><tr><td><div align="center">第5期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s5.jpg' border=0 /></td>
</tr><tr><td><div align="center">第6期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s6.jpg' border=0 /></td>
</tr><tr><td><div align="center">第7期</div></td>
</tr></table></TD><TD align=middle width=85><table cellSpacing=0 cellPadding=0 align=center border=0><tr><td><img
class=imgframe src='http://www.codefans.net/jscss/demoimg/wall_s7.jpg' border=0 /></td>
</tr><tr><td><div align="center">第8期</div></td>
</tr></table></TD>
</TR></TABLE></DIV>
<DIV id=templayer style="LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px"></DIV></TD>
<TD align=middle width=25><img
src="http://www.codefans.net/jscss/demoimg/200905/right.gif" border=0 onmouseout=normal() onmouseover=plusSpeed() /></TD>
</TR></TABLE>
</body>
</html>

⑨ java script 实现可控的图片滚动

<script type="text/javascript">
$("#testtab2").tab({
tabId:"#tabtag2", //切换控制来器的ID
tabTag:"li", //切换控制器标自签
conId:"#tabcon2", //内容容器ID
conTag:"div", //容器标签
act:"click", //点击触发 也可以不设置 默认就为click 设置为 mouseover则为划过
effact: "scrollx", //横向滚动效果
dft:2 //设置起始显示序列
})

</script>

⑩ 求一段js按钮控制图片左右滚动的代码。按钮不点击时,图片不滚动

<!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>
<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}
.img-scroll .next { right:0}
.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>斯蒂芬</li>
<li>啊asdf</li>
<li>请问</li>
<li>阿道夫</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(false);
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.animate({'margin-left':0});
});
if (or == false)
{
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);
</script>

</body>
</html>

阅读全文

与js可控的左右滚动图片相关的资料

热点内容
位置闭环控制c程序 浏览:83
荣耀4x乐动力微信运动 浏览:968
javatimer变化 浏览:615
word如何添加超链接 浏览:574
2014年软考程序员真题 浏览:983
苹果手机在哪买正品 浏览:429
苹果app等待中怎么办 浏览:768
夏新电子狗升级包 浏览:944
tlc5615正弦波代码 浏览:594
word表格2003 浏览:5
javascript本地路径 浏览:418
苹果appstore删除不了 浏览:918
文件被隐藏为系统文件 浏览:746
word中如何插入文本框 浏览:14
苹果4s连不上蜂窝网络 浏览:605
flyme50主动防御系统 浏览:977
酷派大神x7全网通刷别的系统 浏览:120
用什么软件能备份恢复出厂设置密码 浏览:989
nosec大数据 浏览:668
java第一阶段项目 浏览:538