① 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>