js轮播怎么写

1. 新手 , 求大神给写一段Js轮播效果 , 加解释 更好

直接给你JS代码吧,HTML自己写$(document).ready(function(){ var arr = new Array(); arr[0] = document.getElementById("to1").style.src="images/001.png"; arr[1] = document.getElementById("to2").style.src="images/002.png"; arr[2] = document.getElementById("to3").style.src="images/003.png"; arr[3] = document.getElementById("to4").style.src="images/004.png"; var curIndex = 0; //定义开始索引 setInterval(changeImg,1000); //设定轮播,间隔时间function changeImg() { var obj = document.getElementById("bei"); //获得所要设置的元素 if (curIndex == arr.length - 1) { curIndex = 0; } else { curIndex += 1; } obj.style.background = "url(" + arr[curIndex] + ")";//设置获得元素的背景图片 } });原理就是把要轮播图片的路径设为一个集合,然后用遍历集合的方式把图片一个一个的显示出来。

js轮播怎么写

还有好多轮播的方法,这个比较简单,HTML代码自己写吧,不难。

2. 简单的HTML+js图片轮播

h5代码:

<div id="wrap">

<ul id="list">

<li>10</li>

<li>9</li>

<li>8</li>

<li>7</li>

<li>6</li>

<li>5</li>

<li>4</li>

<li>3</li>

<li>2</li>

<li>1</li>

</ul>

</div>

css代码:

<style type="text/css">

@-webkit-keyframes move{

0%{left:-500px;}

100%{left:0;}

}

#wrap{width:600px;height:130px;border:1px solid #000;position:relative;margin:100px auto;

overflow: hidden;}

#list{position:absolute;left:0;top:0;padding:0;margin:0;

-webkit-animation:5s move infinite linear;width:200%;}

#list li{list-style:none;width:120px;height:130px;border:1px solid red;background: pink;

color:#fff;text-align: center;float:left;font:normal 50px/2.5em '微软雅黑';}

#wrap:hover #list{-webkit-animation-play-state:paused;}

</style>

扩展资料:

轮播图就是一种网站在介绍自己的主打产品或重要信息的传播方式。说的简单点就是将承载着重要信息的几张图片,在网页的某一部位进行轮流的呈现,从而做到让浏览者很快的了解到网站想要表达的主要信息。以及各种新闻网站的头版头条都是用这种方式呈现的重要信息。

轮播图的实现方式:例如:有5张轮播的图片,每张图片的宽度为1024px、高度为512px.那么轮播的窗口大小就应该为一张图片的尺寸,即为:1024*512。之后将这5张图片0px水平相接组成一张宽度为:5120px,高度依然为:512px。最后将这张合成后的大图每次向左移动1024px即可实现轮播图。

3. 用jquery实现图片轮播怎么写呢求指教

*{ margin: 0; padding: 0; } ul{ list-style:none; } .slideShow{ width: 620px; height: 700px; /*其实就是图片的高度*/ border: 1px #eeeeee solid; margin: 100px auto; position: relative; overflow: hidden; /*此处需要将溢出框架的图片部分隐藏*/ } .slideShow ul{ width: 2500px; position: relative; /*此处需注意relative : 对象不可层叠,但将依据left,right,top,bottom等属性在正常文档流中偏移位置,如果没有这个属性,图片将不可左右移动*/ } .slideShow ul li{ float: left; /*让四张图片左浮动,形成并排的横着布局,方便点击按钮时的左移动*/ width: 620px; } .slideShow .showNav{ /*用绝对定位给数字按钮进行布局*/ position: absolute; right: 10px; bottom: 5px; text-align:center; font-size: 12px; line-height: 20px; } .slideShow .showNav span{ cursor: pointer; display: block; float: left; width: 20px; height: 20px; background: #ff5a28; margin-left: 2px; color: #fff; } .slideShow .showNav .active{ background: #b63e1a; } js代码规范: 主体代码:[html] view plain copy print?<body> <!--图片布局开始--> <!--图片布局结束--> <!--按钮布局开始--> 1 2 3 4 <!--按钮布局结束--> 。

4. jquery图片轮播代码

最低0.27元开通文库会员,查看完整内容> 原发布者:赵一鸣 Html、js图片轮播代码现在基本上每个网站都有一个自动轮播的banner广告图,在没有任何按钮的情况下,图片在规定的时间内进行自动切换。

下面是html、js图片轮播代码详情。代码效果图实例:第一秒:第二秒:第三秒:详细代码如下:Html代码部分: 1.jpg">2.jpg">3.jpg">Css代码部分:css">ul,li{margin:0px;padding:0px}li{list-style:none}.banner{width:630px;height:250px;margin:100pxauto;overflow:hidden;cursor:pointer}Javascript代码部分:javascript"src="jquery.js">javascript">$(function(){vartimer=setInterval(function(){if($(".bannerli:last").is(":hidden")){$(".bannerli:visible").addClass("on");$(".bannerli[class=on]").next().fadeIn("slow");$(".bannerli[class=on]").hide().removeClass("on");}else{$(".bannerli:last").hide();$(".bannerli:first").fadeIn("slow");}},2000)$(".bannerli").hover(function(){clear。

5. js原生代码实现轮播图

<meta charset="UTF-8"> 最简单的轮播广告 <style> body, div, ul, li { margin: 0; padding: 0; } ul { list-style-type: none; } body { background: #000; text-align: center; font: 12px/20px Arial; } #box { position: relative; width: 492px; height: 172px; background: #fff; border-radius: 5px; border: 8px solid #fff; margin: 10px auto; } #box .list { position: relative; width: 490px; height: 170px; overflow: hidden; border: 1px solid #ccc; } #box .list li { position: absolute; top: 0; left: 0; width: 490px; height: 170px; opacity: 0; transition: opacity 0.5s linear } #box .list li.current { opacity: 1; } #box .count { position: absolute; right: 0; bottom: 5px; } #box .count li { color: #fff; float: left; width: 20px; height: 20px; cursor: pointer; margin-right: 5px; overflow: hidden; background: #F90; opacity: 0.7; border-radius: 20px; } #box .count li.current { color: #fff; opacity: 0.7; font-weight: 700; background: #f60 } </style><body> 1 2 3 4 5 。

6. 怎么用js做一个简单的轮播图

obj1.onmouseover = function () {

clearInterval(time);

}

obj1.onmouseout = function () {

time = setInterval("turn();", 6000);

}

for (var num = 0; num < obj2.length; num++) {

obj2[num].onmouseover = function () {

turn(this.innerHTML);

clearInterval(time);

}

obj2[num].onmouseout = function () {

time = setInterval("turn();", 6000);

}

}

7. jquery简单自动轮播图代码怎么写

html部分 this is the page一 this is the page二 this is the page三 this is the page四 css部分 *{ padding: 0; margin: 0; } html,body{ height: 一00%; } #container { width: 一00%; height: 500px; overflow: hidden; } .sections,.section { height:一00%; } #container,.sections { position: relative; } .section { background-color: #000; background-size: cover; background-position: 50% 50%; text-align: center; color: white; } #section0 { background-image: url('images/一.jpg'); } #section一 { background-image: url('images/二.jpg'); } #section二 { background-image: url('images/三.jpg'); } #section三 { background-image: url('images/四.jpg'); } .pages li{list-style-type:none;width:一0px;height:一0px;border-radius:一0px;background-color:white}.pages li:hover{box-shadow:0 0 5px 二px white}.pages li.active{background-color:orange;box-shadow:0 0 5px 二px orange}.pages{position:absolute;z-index:999}.pages.horizontal{left:50%;transform:translateX(-50%);bottom:5px}.pages.horizontal li{display:inline-block;margin-right:一0px}.pages.horizontal li:last-child{margin-right:0}.pages.vertical{right:5px;top:50%;transform:translateY(-50%)}.pages.vertical li{margin-bottom:一0px}.pages.vertical li:last-child{margin-bottom:0} JS部分 jquery-一.一一.0.min.js" type="text/javascript"> //引入pageSwitch.min.js 如。

8. HTML图片轮播代码怎么写

(1)<div id="butong_net_left" style="width:1000px。

(2);"> <table cellpadding="0" cellspacing="0" border="0"> <tr><td id="butong_net_left1" valign="top" align="center"> <table cellpadding="2" cellspacing="0" border="0"> <tr align="center">

一、数字键控制代码:

(1) <div> <a href="javascript:show(1)"><span id="I1" style="width:18px; text-align:left。(3)background:gray;">1</span></a> <a href="javascript:show(2)"><span id="I2" style="width:18px。

(4)text-align:left;width:18px。

(4)text-align:left;background-color:gray;">2</span></a> <a href="javascript:show(3)"><span id="I3" style="width:18px;text-align:left。

(5)background-color:gray;text-align:left。

(5)background-color:gray;">3</span></a>

9. 手机app滑动轮播原生js怎么写

下面是提供的一个demo: 1、html <meta charset="utf-8"/><meta , body{ font-size:9px; }}@media screen and (min-width:320px) { html, body{ font-size:12px; }}@media screen and (min-width:480px) { html, body{ font-size:18px; }}@media screen and (min-width:640px) { html, body{ font-size:24px; }}@media screen and (min-width:960px) { html, body{ font-size:36px; }}div.imgbox{width:25rem;height:16.5rem;overflow:hidden;margin:0 auto;}div.imgbox ul{clear:both;width:75rem;}div.imgbox ul li{float:left;width:25rem;height:16.5rem;overflow:hidden;text-align:center;}div.imgbox ul li img{width:24rem;height:16.5rem;}#page{color:red;}</style><body> 这里通过回调显示当前滚动到多少页:0 2、核心滑动脚本代码 (function($){/* 图片滚动效果 add 2014-05-14 by js明哥哥 博客地址:/u/huzhiming/ @jQuery or @String box : 滚动列表jQuery对象或者选择器 如:滚动元素为li的外层ul @object config : { @Number width : 一次滚动宽度,默认为box里面第一个一级子元素宽度[如果子元素宽度不均匀则滚动效果会错乱] @Number size : 列表长度,默认为box里面所有一级子元素个数[如果size不等于一级子元素个数,则不支持循环滚动] @Boolean loop : 是否支持循环滚动 默认 true @Boolean auto : 是否自动滚动,支持自动滚动时必须支持循环滚动,否则设置无效,默认为true @Number auto_wait_time : 自动轮播一次时间间隔,默认为:3000ms @Function callback : 滚动完回调函数,参入一个参数当前滚动节点索引值 }*/function mggScrollImg(box,config){ this.box = $(box); this.config = $.extend({},config||{}); this.width = this.config.width||this.box.children().eq(0).width();//一次滚动的宽度 this.size = this.config.size||this.box.children().length; this.loop = this.config.loop||true;//默认能循环滚动 this.auto = this.config.auto||true;//默认自动滚动 this.auto_wait_time = this.config.auto_wait_time||3000;//轮播间隔 this.scroll_time = 300;//滚动时长 this.minleft = -this.width*(this.size-1);//最小left值,注意是负数[不循环情况下的值] this.maxleft =0;//最大lfet值[不循环情况下的值] this.now_left = 0;//初始位置信息[不循环情况下的值] this.point_x = null;//记录一个x坐标 this.point_y = null;//记录一个y坐标 this.move_left = false;//记录向哪边滑动 this.index = 0; this.busy = false; this.timer; this.init();}$.extend(mggScrollImg.prototype,{ init : function(){ this.bind_event(); this.init_loop(); this.auto_scroll(); }, bind_event : function(){ var self = this; self.box.bind('touchstart',function(e){ if(e.touches.length==1 && !self.busy){ self.point_x = e.touches[0].screenX; self.point_y = e.touches[0].screenY; } }).bind('touchmove',function(e){ if(e.touches.length==1 && !self.busy){ return self.move(e.touches[0].screenX,e.touches[0].screenY);//这里根据返回值觉得是否阻止默认touch事件 } }).bind('touchend',function(e){ !self.busy && self.move_end(); }); }, /* 初始化循环滚动,当一次性需要。