⑴ js实现div自动在窗口左右移动
<!DOCTYPEHTML>
<html>
<head>
<metacharset=utf-8/>
<title>UFO来了</title>
<script>
window.onload=function(){
vari=10;
varj=0;
vare=target;
varwin=document.documentElement||.body;
functionintern(){
varwidth=e.clientWidth;
varheight=e.clientHeight;
varleft=parseFloat(e.style.left);
vartop=parseFloat(e.style.top);
varwindowWidth=win.clientWidth;
varwindowHeight=win.clientHeight;
if(windowWidth-width<(left+i)){
i=-i;
}elseif((left+i)<0){
i=-i;
}
if(windowHeight-height<(top+j)){
j=-j;
}elseif((top+j)<0){
j=-j;
}
e.style.left=left+i+"px";
e.style.top=top+j+"px";
}
setInterval(intern,30);
};
</script>
</head>
<body>
<divid="target"style="border-radius:90px;background-color:red;width:30px;height:30px;position:absolute;top:100px;left:0px;"></div>
</body>
</html>
⑵ 做图片轮播功能(要一直从右往左播,不断的循环),js怎么写看一下我的代码给我讲几句重要的代码
你把整个ul想成是一张图片,你要做的就是把ul左右移动,然后在ul外面可以套一个div,样式为{overflow:hidden},关回于复位答,你可以用%运算,当移动到最后一个li的时候,跳到第一个li去。
⑶ js图片左右滚动 怎么弄 有没案例代码 求帮忙
1.jquery.imgScroll.js
;(function($){$.fn.extend({"imgScroll":function(object){object=$.extend({firstDiv:null,scrollBox:null,scrollImgBox:null,tabDiv:null,tabDivList:null,botPrev:null,botNext:null,changeType:"slide",thumbNowClass:'on',thumbOverEvent:true,changeTime:5000,ImgBoxMar:0,flag:true},object||{});varimgLen=$(object.scrollImgBox).length;varimgNum=0;vartabNum=0;varnowIndex=0;varindex;varscrollWid=$(object.scrollImgBox).width()+object.ImgBoxMar;$(object.scrollImgBox).clone().appendTo($(this));functionchangeEffectNext(){if(object.changeType=='slide'){if(imgNum<imgLen){imgNum++}else{if(imgNum==imgLen){$(object.scrollBox).css({'margin-left':0});imgNum=1}}$(object.scrollBox).animate({'margin-left':-scrollWid*imgNum});if(tabNum<imgLen-1){tabNum++}else{if(tabNum==imgLen-1){tabNum=0}}$(object.tabDivList).eq(tabNum).addClass(object.thumbNowClass);$(object.tabDivList).eq(tabNum).siblings().removeClass(object.thumbNowClass)}if(object.changeType=='fadein'){if(imgNum<imgLen-1){imgNum++}else{if(imgNum==imgLen-1){imgNum=0}}$(object.scrollImgBox).eq(imgNum).fadeIn('slow');$(object.scrollImgBox).eq(imgNum).siblings().fadeOut('slow');$(object.tabDivList).eq(imgNum).addClass(object.thumbNowClass);$(object.tabDivList).eq(imgNum).siblings().removeClass(object.thumbNowClass)}};functionchangeEffectPrev(){if(object.changeType=='slide'){if(imgNum>0){imgNum--}else{if(imgNum==0){$(object.scrollBox).css({'margin-left':-scrollWid*imgLen});imgNum=imgLen-1}}$(object.scrollBox).animate({'margin-left':-scrollWid*imgNum});if(tabNum>0){tabNum--}else{if(tabNum==0){tabNum=imgLen-1}}$(object.tabDivList).eq(tabNum).addClass(object.thumbNowClass);$(object.tabDivList).eq(tabNum).siblings().removeClass(object.thumbNowClass)}if(object.changeType=='fadein'){if(imgNum>0){imgNum--}else{if(imgNum==0){imgNum=imgLen-1}}$(object.scrollImgBox).eq(imgNum).fadeIn('slow');$(object.scrollImgBox).eq(imgNum).siblings().fadeOut('slow');$(object.tabDivList).eq(imgNum).addClass(object.thumbNowClass);$(object.tabDivList).eq(imgNum).siblings().removeClass(object.thumbNowClass)}}if(object.flag==true){vars=setInterval(changeEffectNext,object.changeTime);$(object.firstDiv).hover(function(){clearInterval(s)},function(){s=setInterval(changeEffectNext,object.changeTime);});$(object.tabDiv).hover(function(){clearInterval(s)},function(){s=setInterval(changeEffectNext,object.changeTime)});$(object.botPrev).bind("click",function(){clearInterval(s)}).bind("mouseover",function(){clearInterval(s)});$(object.botNext).bind("click",function(){clearInterval(s)}).bind("mouseover",function(){clearInterval(s)})};$(object.botNext).click(function(){changeEffectNext()});$(object.botPrev).click(function(){changeEffectPrev()});functionchangesmallImg(index){$(object.tabDivList).eq(index).addClass(object.thumbNowClass);$(object.tabDivList).eq(index).siblings().removeClass(object.thumbNowClass);if(object.changeType=='slide'){$(object.scrollBox).animate({'margin-left':-scrollWid*index})}if(object.changeType=='fadein'){$(object.scrollImgBox).eq(index).fadeIn('slow');$(object.scrollImgBox).eq(index).siblings().fadeOut('slow')}imgNum=index;tabNum=index}if(object.thumbOverEvent==true){$(object.tabDivList).click(function(){varindex=$(this).index();changesmallImg(index)})}if(object.thumbOverEvent==false){$(object.tabDivList).hover(function(){varindex=$(this).index();changesmallImg(index)})}}})})(jQuery);
2.html结构
a,.lbPeo{-webkit-transition:all.2sease-in-out0s;-o-transition:all.2sease-in-out0s;-moz-transition:all.2sease-in-out0s;-ms-transition:all.2sease-in-out0s;transition:all.2sease-in-out0s;}
.lbCon{margin-top:33px;margin-bottom:37px;position:relative;}
.lbBtn{display:block;position:absolute;top:0;width:40px;height:143px;border:1pxsolid#D7D2CA;background:url('../../../images/special/140801/ctr_prev.png')no-repeatcentercenter;}
.lbPrev{left:0}.lbNext{right:0;background-image:url('../../../images/special/140801/ctr_next.png')}
.lbBtn:hover{background-color:#ddd;}
.lbBox{width:900px;height:145px;margin-left:50px;overflow:hidden;position:relative;}
.lbList{width:1000%;}
.lbBoxul{float:left}
.lbBoxli{float:left;width:150px;height:145px;overflow:hidden;}
.lbPeo{text-align:center;line-height:18px;font-family:"微软雅黑";color:#333}
.lbPeoimg{display:block;border:1pxsolid#ddd;width:84px;height:103px;margin-left:32px;*margin-left:5px;}
.lbPeoh5{font-weight:bold;font-size:12px;padding-top:5px;*padding-top:0}
.lbPeoh6{font-size:12px;}
.lbBoxlia:hover{text-decoration:none}
.lbBoxlia:hover.lbPeo{color:#ff9600}
<!--人物-->
<divclass="lbConcomWithclearfix">
<divclass="lbBox">
<divclass="lbList">
<ul>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
</ul>
<ul>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大2红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李2大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
<li><ahref=""target="_blank">
<divclass="lbPeoclearfix">
<imgsrc="http://img4.cache.netease.com/stock/2014/7/22/201407221627281cd88.jpg"/>
<h5>李大红</h5>
<h6>大公报副社长兼执行总编辑</h6>
</div>
</a></li>
</ul>
</div>
</div>
<ahref="javascript:;"class="lbBtnlbPrev"></a>
<ahref="javascript:;"class="lbBtnlbNext"></a>
</div>
3.页面调用:
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery.imgScroll.js"></script>(上面那个js)
$('.lbCon.lbBox.lbList').imgScroll({
firstDiv:'.lbCon.lbBox',
scrollBox:'.lbCon.lbBox.lbList',
scrollImgBox:'.lbCon.lbBoxul',
botPrev:'.lbCon.lbPrev',
botNext:'.lbCon.lbNext',
changeType:"slide",
thumbNowClass:'on',
thumbOverEvent:true,
changeTime:5000,
ImgBoxMar:0,
flag:false
});
4.至于鼠标滑过 显示左右按钮,可以这么写(思路:css默认隐藏左右按钮,鼠标滑过显示左右按钮,划出隐藏,需要引入jquery.js)
$(function(){
$(".wj_jdt_1").bind("onmouseover",function(){
$(".ctr_btn").show();
}).bind("onmouseout",function(){
$(".ctr_btn").hide();
})
})
大体是这么个意思,至于怎么延伸在你
⑷ js 给li设置了右外边距且左浮动,当li达到4个时,自动换行显示且第4个li的右边距自动删除
<metacharset="utf-8"/>
<style>
a{color:#fff;}
ul,ol,li{
list-style:noneoutsidenone;
padding:0;
margin:0;
}
#list{
width:430px;
overflow:hidden;
background:#cecece;
}
#listli{
width:100px;
float:left;
margin-right:10px;
margin-bottom:20px;
background:#333;
}
</style>
<ulid="list">
<li><ahref="#">1</a></li>
<li><ahref="#">2</a></li>
<li><ahref="#">3</a></li>
<li><ahref="#">4</a></li>
<li><ahref="#">5</a></li>
<li><ahref="#">6</a></li>
<li><ahref="#">7</a></li>
<li><ahref="#">8</a></li>
<li><ahref="#">9</a></li>
<li><ahref="#">10</a></li>
<li><ahref="#">11</a></li>
<li><ahref="#">12</a></li>
<li><ahref="#">13</a></li>
</ul>
<script>
functiondel4margin(x){
varObjLi=document.getElementById("list").getElementsByTagName("li");
for(vari=1;i<ObjLi.length;i++){
if(i%x==0&&i!==0){
ObjLi[i-1].style.background="red";
ObjLi[i-1].style.marginRight="0";
}
}
}
window.onload=del4margin(4);//传入参数4,去掉第4个li的外边距
</script>
⑸ 关于javascript中菜单栏过长 实现左右箭头滑动项~
<style>
ul{
margin:0px;
padding:0px;
}
li{
float:left;
cursor:pointer;
}
.map_div{
width:900px;
height:40px;
background-color:#000000;
overflow:hidden;
}
#dh_li{
width:800px;
height:40px;
background-color:#000000;
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
text-overflow:ellipsis;
display:block;
after:content:"...";
}
#dh_li li{
width:150px;
height:40px;
background-color:#000000;
color:#FF0000;
border-right:1px solid #FF0000;
text-align:center;
padding-top:10px;
overflow:hidden;
}
#dh_li li a:link{
color:#FF0000;
}
#dh_li li a:visited{
color:#FF0000;
}
#dh_li li a:hover{
color:#FF0000;
}
.dh_li{
width:50px;
height:40px;
font-size:20px;
font-weight:bold;
color:#FF0000;
text-align:center;
padding-top:10px;
background-color:#CCCCCC;
}
</style>
<body>
<div class="map_div">
<ul>
<li id="dh_li">
<div style="width:1500px;">
<ul>
<li><a href="#">网站首页</a></li>
<li><a href="#">公司简介</a></li>
<li><a href="#">产品展示</a></li>
<li><a href="#">新闻咨询</a></li>
<li><a href="#">热点咨询</a></li>
<li><a href="#">合作伙伴</a></li>
<li><a href="#">网站论坛</a></li>
<li><a href="#">在线咨询</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</div>
</li>
<li id="left_" class="dh_li" onclick="move_left();">←</li>
<li id="right_" class="dh_li" onclick="move_right();">→</li>
</ul>
</div>
</body>
<script>
var demo=document.getElementById("dh_li");
function move_right()
{
if(dh_li.scrollLeft<=(1500-800))
dh_li.scrollLeft+=150;
}
function move_left()
{
if(dh_li.scrollLeft>=0)
dh_li.scrollLeft-=150;
}
</script>
⑹ 怎么用js实现类似手机切屏的左右滑动的效果
这是自己复封装的原生js方法,为了制偷懒,用了电jqurey。调用方法如下:
touchs._left(object);//往左滑动,
touchs._right(object);//往右滑动
touchs._top(object);//往上滑动
touchs._bottom(object);//往下滑动
说明:object的取值可以是一个id("#id")表达式,或者是一个样式表达式(".class"),或者标签的属性表达式("div[id=id]")等,只要可以用jqurey通过这个表达式获取到dom对象,这个表达式怎么写都可以。