刚接触js不久,自己写的banner幻灯片效果。
对于我这种菜鸟来讲,刚接触项目。叫我用插件,其实我说插件太臃肿不想用,倒不如说我是看不懂那些插件。。。- -(更愿意自己写点看得懂的代码,顺便也是个学习的过程)
所以自己花了些时间,自己来写了个demo, 效果很简单。(求轻喷-_-)
下面我就直接贴上代码了
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="description" content="" />
<meta name="Keywords" content="" />
<title>cfjc</title> <!--[if lt IE 9]><script type="text/javascript" src="http://www.ruifox.com/resouce/js/company/html5.js"></script><![endif]-->
<style type="text/css">
.left{float:left;}
.right{float:right;}
.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0}
.clearfloat{zoom:1}
body{margin:0; padding:0;}
ul{margin:0; padding:0;}
.wp {width:1000px; margin:0 auto;position:relative;}
li{list-style:none;}
a{text-decoration:none;}
a:hover{text-decoration:underline;}
.nobrder{border-right:none;}
#banner{width:100%; height:500px; position:relative;}
#banner ul {position:relative; min-width:4000px;height: 500px;z-index: 0}
.bnnwp {position:relative;overflow:hidden; width:100%; z-index:40;}
#banner ul li{float:left; min-width:1000px; height:500px;}
#banner ul .b1{background:#423134 url(../images/banner01.jpg) no-repeat center center;}
#banner ul .b2 {background:#45239A;}
#banner ul .b3 {background:#45123A;}
#banner ul .b4{background:#46193A;}
#banner .nextbtn{position:absolute; top:40%;right:50px; z-index:43}
#banner .prvebtn{position:absolute; top:40%;left:50px;z-index:43}
.nextbtn{width:22px; height:43px; background:url(../images/next_hover.png) no-repeat; cursor:pointer; font-size:28px; color:#fff;}
.nextbtn:hover{ background:url(../images/next.png) no-repeat;}
.prvebtn{width:22px; height:43px; background:url(../images/prev.png) no-repeat;cursor:pointer; font-size:28px; color:#fff;}
.prvebtn:hover{ background:url(../images/prev_hover.png) no-repeat;}
#bancontr{position:absolute;bottom:20px; right:100px;z-index:42;}
.heighlight_tip span{display:inline-block;*zoom:1; font-size:28px; color:#fff; *display:inline; width:14px;height:14px; border-radius:50%; text-indent:6px; color:#fff; background:#61676C; line-height:21px; margin-left:10px;cursor:pointer; behavior: url(../images/pie/PIE.htc);}
.heighlight_tip .current{background:#006ba4; no-repeat;}
</style>
</head>
<body>
<section id="banner">
<div class="bnnwp"><ul class="clearfloat">
<li style="background: url("http://chengfei-en.brandmarketingsite.com/uploadfile/2014/0106/20140106014754577.jpg") no-repeat center "></li>
<li style="background: url("http://chengfei-en.brandmarketingsite.com/uploadfile/2014/0106/20140106041757808.jpg") no-repeat center"></li>
<li style="background: url("http://chengfei-en.brandmarketingsite.com/uploadfile/2014/0106/20140106041812272.jpg") no-repeat center"></li>
<li style="background: url("http://chengfei-en.brandmarketingsite.com/uploadfile/2014/0106/20140106041820216.jpg") no-repeat center"></li>
</ul>
</div>
<div class="prvebtn"><</div>
<div class="nextbtn">></div>
<div id="bancontr">
<div class="heighlight_tip">
<span class="current" ></span>
<span></span>
<span></span>
<span></span>
<div style="clear:both"></div>
</div>
</div>
</section>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var index="";
var timer="";
var index="";
var leng=$("li").size();
testLiw(); //banner ——UL宽度设置; 用于自适应屏幕宽度!
$(window).resize(function() {
testLiw();
}); function testLiw(){ Lwith=$("body").width();
xl=(leng+2)*Lwith;
$("#banner ul").width(xl);
$("#banner ul li").width(Lwith);
showpicSet(index);
} var sWidth=$("li").width(Lwith);
$("#banner ul").css("width", Lwith*(leng+2)); //设置ul的宽度;
$("#banner ul").prepend($("#banner ul li:last").clone()); //为了实现滑动更好的效果你懂的、
$("#banner ul").append($("#banner ul li:eq(1)").clone());
$("#banner ul").css("left", -Lwith+"px"); //初始化幻灯片的位置! $(".heighlight_tip span").mouseover(function(){
index=$(".heighlight_tip span").index(this);
showpic(index);
}).eq(0).click(); //class="current" 初始化按钮位置! $(".prvebtn").click(function(){prve();});
$(".nextbtn").click(function(){next();}); function next(){
if(index==leng-1){
index=0;
showlast();
}else{
index++;
showpic(index); }} ; //下一页
function prve(){
if(index==0){index=leng-1;
showfirst();
}
else{
index--;
showpic(index);}} //上一页 function showpicSet(index){ //我也不知道为什么把这个函数写在这下面了,--用来调整在幻灯片播放过程中,自适应屏幕本身的宽度。
var nowLeft= (-index-1)*Lwith;
$(".bnnwp ul").stop(true,false).css('left',nowLeft);
}
function showpic(index){
var nowLeft= (-index-1)*Lwith;
$("#banner ul").stop(true,true).animate({'left':nowLeft},700);
$(".heighlight_tip span").removeClass("current").eq(index).addClass("current");
} function showlast(){ //最后一张跳到第一张的函数
var nowLeft=(-leng-1)*Lwith;
$("#banner ul").stop(true,false).animate({'left':nowLeft},700,function(){
$("#banner ul").css('left',-Lwith+'px');
})
$(".heighlight_tip span").removeClass("current").eq(0).addClass("current");
} function showfirst(){ //第一张跳到最后一张的函数
var nowleft=(-leng)*Lwith;
$("#banner ul").stop(true,false).animate({'left':"0px"},700,function(){
$("#banner ul").css('left',nowleft+'px');
})
$(".heighlight_tip span").removeClass("current").eq(leng-1).addClass("current");
} $("#banner").hover(function(){
clearInterval(timer);},
function(){timer=window.setInterval(function(){next();},6000); }).mouseout(); </script>
</body>
</html>
//自己都觉得代码写的太冗长了,还请各位大神们多多批评啊,帮小弟我指出些错误。。- -
刚接触js不久,自己写的banner幻灯片效果。的更多相关文章
- 刚接触js感觉好吃力啊
我是一个新手,最近刚刚开始学习js这门语言,感觉好难,有一种无从下手的感觉,不知道应该从哪里学习,虽然也看了很多的书,但是对于一个没有计算机基础的人来说,真的是一种煎熬,每一个名词都要去查.万事开头难 ...
- turn.js中文API 写一个翻页效果的参数详细解释
$('.flipbook').turn({ width: 922, height: 600, elevation: 50, gradients: true, a ...
- java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误
java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误. 问题: 创建了一个工 ...
- 刚接触HTML5应该先学哪里才好?
好吧,话不多说,直接来点干货吧! 刚接触html的小白都感觉摸不着头脑?应该怎么学习呢,其实HTML5可能对于还没有接触过的小白来说会比较的难,听起来也比较新颖.这是个什么骚东西!其实不然,这个就是构 ...
- 刚接触SkyLine的一点小收获与感触
因为刚接触Skyline不到一个星期,也怕把学习到的忘记掉,所以写一点学习到的一些皮毛的东西,赶紧记录一下,怕回头忘记 1.网上关于web端的开发非常多,也有很多牛人分享自己的经验,所以学习起来也相对 ...
- JS基于时间戳写的浏览访问人数
Title:JS基于时间戳写的浏览访问人数 --2013-12-23 14:07 <script language="JavaScript"> var timesta ...
- 如何把js的代码写的更加容易维护(一)--面向对象编程
总是头疼javascript的代码写起来不可维护,那么看看下面的代码: (function (w, $) { var app = { init: function () { var me = this ...
- 用node.js从零开始去写一个简单的爬虫
如果你不会Python语言,正好又是一个node.js小白,看完这篇文章之后,一定会觉得受益匪浅,感受到自己又新get到了一门技能,如何用node.js从零开始去写一个简单的爬虫,十分钟时间就能搞定, ...
- 2019前端面试系列——JS高频手写代码题
实现 new 方法 /* * 1.创建一个空对象 * 2.链接到原型 * 3.绑定this值 * 4.返回新对象 */ // 第一种实现 function createNew() { let obj ...
随机推荐
- php 文本框里面显示数据库调出来的资料
php 文本框里面显示数据库调出来的资料,,,在里面我标注了,,那个地方为什么是!=才能显示正确的数据库资料啊?我理解的是对比正确输出数据库内容的.大师貌似不知道为什么就写错了 <html> ...
- java 检查是否是数组 检查是否是空数组 检查数组是否包含某个元素
/** * Determine whether the given object is an array: * either an Object array or a primitive array. ...
- java传递json数据到前台jsp
在数据传输流程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键.例如: JSON字符串: var str1 = '{ &q ...
- winform 窗体关闭按钮禁用、不显示最大化、最小化、关闭按钮 分类: WinForm 2014-12-22 16:09 82人阅读 评论(0) 收藏
关闭按钮禁用: (1) FormClosing事件 private void Main_FormClosing(object sender, FormClosingEventArgs e) { ...
- Java处理文件小例子--获取全国所有城市的坐标
需求:前端展示数据,全国城市的坐标
- 【Android笔记】MediaPlayer基本使用方式
Android MediaPlayer基本使用方式 使用MediaPlayer播放音频或者视频的最简单样例: JAVA代码部分: public class MediaPlayerStudy exten ...
- android软键盘的用法总结
1.软键盘的显示原理 软键盘其实是一个Dialog.InputMethodService为我们的输入法创建了一个Dialog,并且对某些参数进行了设置,使之能够在底部 或者全屏显示.当我们点击输入框时 ...
- 手机相机ISO是什么
要说什么是ISO还要从传统胶片相机说起,ISO被 称为感光度,它是衡量传统相机所使用胶片感光速度的国际统一指标,其数值反映了胶片感光时的速度(其实是银元素与光线的光化学反应速率).而对于现在并不 使用 ...
- android 21 隐式意图启动系统预定义activity
Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity, ...
- systrace跟踪 Android性能优化
http://blog.csdn.net/oujunli/article/details/8138172 http://blog.csdn.net/oujunli/article/details/50 ...