網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > 綜合知識 > 

js輪播怎麼寫

欄目: 綜合知識 / 發佈於: / 人氣:1.62W
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(); }); }, /* 初始化循環滾動,當一次性需要。

Tags:js 輪播