样式
代码如下:
#div_left{float:left;width:60px;height:86px;}
#starScroll{width:843px;height:188px;margin-left:15px;margin-right:15px;padding-top:9px;overflow:hidden;border:1px solid red;float:left;}
#starScroll #contentScroll{width:500%}
#starScroll #ScrollOne{float:left;}
#starScroll #ScrollOne a{float:left;width:204px;height:188px;margin-right:9px;float:left;display:inline;}
#starScroll #ScrollOne img{width:204px;height:188px;border:0px;}
#starScroll #ScrollTwo{float:left;}
#starScroll #ScrollTwo a{float:left;width:204px;height:188px;margin-right:9px;float:left;display:inline;}
#starScroll #ScrollTwo img{width:204px;height:188px;border:0px;}
#div_right{float:left;width:60px;height:86px;}
.arrow{background:url(p_w_picpaths/arrow.png) no-repeat;cursor:pointer;height:86px;width:60px;cursor:pointer;display:block;margin-top:50px;}
.prev{background-position:left top;}
.prev:hover{background-position:left bottom;}
.next{background-position:right top;}
.next:hover{background-position:right bottom;}
html代码
代码如下:
<div>
<div id="div_left">
<span id="btn_left" class="arrow prev"></span>
</div>
<div id="starScroll">
<div id="contentScroll">
<div id="ScrollOne">
<a href="#" title="1"><img src="p_w_picpaths/1.jpg" /></a>
<a href="#" title="2"><img src="p_w_picpaths/2.jpg" /></a>
<a href="#" title="3"><img src="p_w_picpaths/3.jpg" /></a>
<a href="#" title="4"><img src="p_w_picpaths/4.jpg" /></a>
<a href="#" title="5"><img src="p_w_picpaths/5.jpg" /></a>
<a href="#" title="6"><img src="p_w_picpaths/6.jpg" /></a>
<a href="#" title="7"><img src="p_w_picpaths/7.jpg" /></a>
<a href="#" title="8"><img src="p_w_picpaths/8.jpg" /></a>
</div>
<div id="ScrollTwo"></div>
</div>
</div>
<div id="div_right">
<span id="btn_right" class="arrow next"></span>
</div>
</div>
JS代码
代码如下:
unity3d http://www.unitymanual.com/
<script type="text/javascript">
var Scroll=(function(){
return function(){
var starScroll = document.getElementById("starScroll"),
ScrollOne = document.getElementById("ScrollOne"),
aCollection = ScrollOne.getElementsByTagName("a"),
aLength = aCollection.length,
ScrollTwo = document.getElementById("ScrollTwo"),
btn_left = document.getElementById("btn_left"),
btn_right = document.getElementById("btn_right");
var Width = 204,Current = 1,Rate = 7,TimeTimeout=1000,TimeInterval=10,MarginRight=9;
var SInterval=null,STimeout=null;
var flag=true;
function ScrollLeft(){
var CountWidth = Current*Width+Current*MarginRight,
SLeftPara=starScroll.scrollLeft;
if(ScrollTwo.offsetWidth-SLeftPara==0){
starScroll.scrollLeft=0;
Current=0;
}
if(CountWidth-SLeftPara==0){
Forward();
}
else{
var v = Math.round((CountWidth-SLeftPara)/Rate);
v = v<1 ? 1 : v;
SetScrollLeft(SLeftPara+v);
}
}
function SetScrollLeft(scrollleft){
starScroll.scrollLeft=scrollleft;
}
function Init(){
flag=false;
SInterval=setInterval(ScrollLeft,TimeInterval);
}
function Forward(){
clearInterval(SInterval);
Current++;
flag=true;
STimeout = setTimeout(Init,TimeTimeout);
}
btn_right.onclick=function(){
if(flag){
clearTimeout(STimeout);
Init();
}
}
function ScrollRight(){
var CountWidth = Current*Width+Current*MarginRight,
SLeftPara = starScroll.scrollLeft;
if(CountWidth-SLeftPara==0){
Forward();
}
else{
var v = Math.round((CountWidth-SLeftPara)/Rate);
v = v>-1?-1:v;
SetScrollLeft(SLeftPara+v);
}
}
btn_left.onclick=function(){
if(!flag){
return;
}
flag=false;
clearTimeout(STimeout);
if(Current==1){
SetScrollLeft(ScrollTwo.offsetWidth);
Current=aLength+1;
}
Current-=2;
SInterval = setInterval(ScrollRight,TimeInterval);
}
if(aLength>0){
starScroll.scrollLeft=0;
ScrollTwo.innerHTML = ScrollOne.innerHTML;
STimeout = setTimeout(Init,TimeTimeout);
}
}
})();
Scroll();
</script>
js图片向右一张张滚动效果实例代码
原创
©著作权归作者所有:来自51CTO博客作者xiaoxuanyunmeng的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
轻松复现一张AI图片
现在有一个非常漂亮的AI图片,你是不是想知道他是怎么生成的?今天我会交给大家三种方法,学会了,什么图都可以手到擒来了。
AIGC stable diffusion 程序那些事 -
Linux Debian12使用flameshot或gnome-screenshot和ImageMagick垂直合并多张图片后组成一张滚动长图
在发布博客,有时需要滚动截长图,虽然在windows系统有滚动截长图的工具,例如:FastStone Capture等,但是Linux Debian系统,这种滚动截长图的工具没有找到合适的。经过自己筛选验证,发现Linux Debian12使用flameshot或gnome-screenshot截取多张图片,再使用和ImageMagick图像处理工具进行垂直合并多张图片,这样就可以组合成一张滚动长
图像处理 linux debian flameshot ImageMagick -
打印机不断打印出一张张空白纸——好像跟技术无关
一次打印机不断打印白纸的处理过程
打印机不断打印白纸 -
Python--随机漫步,生成了一张张超级好看的图
N个点自动生成的图片确定不来看看? ...
python 初始化 颜色渐变 坐标轴