当前位置:首页 > 代码 > 正文

图片自动轮换js代码(图片自动轮换js代码是什么)

admin 发布:2022-12-19 16:01 138


本篇文章给大家谈谈图片自动轮换js代码,以及图片自动轮换js代码是什么对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求JS图片轮换代码,图片切换到最后一张时停止,出现弹出层,提示图片已到最后一张

就是在最后一张的时候加一个判断被~如果是最后一张了,那么就弹出个窗口,最好是把图片都封装进数组,这样就好判断是不是最后一张了~

简单的HTML+js图片轮播?

h5代码:

div id="wrap"

ul id="list"

li10/li

li9/li

li8/li

li7/li

li6/li

li5/li

li4/li

li3/li

li2/li

li1/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即可实现轮播图。

js代码实现banner图片轮播

这是我以前写过的一个,样式你改一下就OK了

div class="fbanner widget3924"

div id="i_focus"

div id="i_focus_pic"

ul id="i_focus_piclist"

li style="display: none;"

a href="" target="_blank" style="background: url(/templates/runlinjinguan/images/banner1.jpg) center 0 no-repeat;"

/a

/li

li style="display: list-item;"

a href="" target="_blank" style="background: url(/templates/runlinjinguan/images/banner4.jpg) center 0 no-repeat;"

/a

/li

li style="display: none;"

a href="" target="_blank" style="background: url(/templates/runlinjinguan/images/banner3.jpg) center 0 no-repeat;"

/a

/li

li style="display: none;"

a href="" target="_blank" style="background: url(/templates/runlinjinguan/images/banner2.jpg) center 0 no-repeat;"

/a

/li

/ul

div id="i_focus_opdiv"

/div

ul id="i_focus_btn"

li id="p0" class=""

span

/span

/li

li id="p0" class="i_cur"

span

/span

/li

li id="p0" class=""

span

/span

/li

li id="p0" class=""

span

/span

/li

/ul

/div

/div

script type="text/javascript" src="/templates/runlinjinguan/js/flash.js"/script

script type="text/javascript"

$("#i_focus_btn").find("li").eq(0).addClass("i_cur");

/script

/div

引用的js文件

// JavaScript Document

//flash js

$(document).ready(function () {

var i_curIndex = 0;

var beauBeauSlide; //函数对象

var i_curID = 0; //取得鼠标下方的对象ID

var pictureID = 0; //索引ID

$("#i_focus_piclist li").eq(0).show(); //默认

autoScroll();

$("#i_focus_btn li").hover(function (e) {

StopScrolll();

$("#i_focus_btn li").removeClass("i_cur") //所有的li去掉当前的样式加上正常的样式

$(this).addClass("i_cur"); //而本身则加上当前的样式去掉正常的样式

i_curID = $(this).attr("id"); //取当前元素的ID

pictureID = $("#i_focus_btn li").index(this);// i_curID.substring(i_curID.length - 1); //取最后一个字符

$("#i_focus_piclist li").eq(pictureID).fadeIn("slow"); //本身显示

$("#i_focus_piclist li").not($("#i_focus_piclist li")[pictureID]).hide(); //除了自身别的全部隐藏

$("#i_focus_tx li").hide();

$("#i_focus_tx li").eq(pictureID).show();

},

function () {

//当鼠标离开对象的时候获得当前的对象的ID以便能在启动自动时与其同步

i_curID = $(this).attr("id"); //取当前元素的ID

pictureID = i_curID.substring(i_curID.length - 1); //取最后一个字符

i_curIndex = pictureID;

autoScroll();

});

//自动滚动

function autoScroll() {

var myNubli = $("#i_focus_btn li").size();

if (myNubli 1) {

$("#i_focus_btn li:last").removeClass("i_cur");

$("#i_focus_tx li:last").hide();

$("#i_focus_btn li").eq(i_curIndex).addClass("i_cur");

$("#i_focus_btn li").eq(i_curIndex - 1).removeClass("i_cur");

$("#i_focus_tx li").eq(i_curIndex).show();

$("#i_focus_tx li").eq(i_curIndex - 1).hide();

$("#i_focus_piclist li").eq(i_curIndex).fadeIn("slow");

$("#i_focus_piclist li").eq(i_curIndex - 1).hide();

i_curIndex++;

i_curIndex = i_curIndex = myNubli ? 0 : i_curIndex;

beauBeauSlide = setTimeout(autoScroll, 5000);

}

}

function StopScrolll() //当鼠标移动到对象上面的时候停止自动滚动

{

clearTimeout(beauBeauSlide);

}

});

//第二个渐隐幻灯开始

var defaultOpts = {

interval: 3000,

fadeInTime: 800,

fadeOutTime: 500

};

var _titles = $("ul.slide-txt li");

var _titles_bg = $("ul.op li");

var _bodies = $("ul.slide-pic li");

var _count = _titles.length;

var _current = 0;

var _intervalID = null;

var stop = function () {

window.clearInterval(_intervalID);

};

var slide = function (opts) {

if (opts) {

_current = opts.current || 0;

} else {

_current = (_current = (_count - 1)) ? 0 : (++_current);

};

_bodies.filter(":visible").fadeOut(defaultOpts.fadeOutTime,

function () {

_bodies.eq(_current).fadeIn(defaultOpts.fadeInTime);

_bodies.removeClass("cur").eq(_current).addClass("cur");

});

_titles.removeClass("cur").eq(_current).addClass("cur");

_titles_bg.removeClass("cur").eq(_current).addClass("cur");

}; //endof slide

var go = function () {

stop();

_intervalID = window.setInterval(function () {

slide();

},

defaultOpts.interval);

}; //endof go

var itemMouseOver = function (target, items) {

stop();

var i = $.inArray(target, items);

slide({

current: i

});

}; //endof itemMouseOver

_titles.hover(function () {

if ($(this).attr('class') != 'cur') {

itemMouseOver(this, _titles);

} else {

stop();

}

},

go);

//_titles_bg.hover(function() { itemMouseOver(this, _titles_bg); }, go);

_bodies.hover(stop, go);

go();

var slideX = {

_this: $('.catalog .imgbox'),

_btnLeft: $('.catalog .left'),

_btnRight: $('.catalog .right'),

init: function () {

slideX._btnLeft.click(slideX.slideLeft);

slideX._btnRight.click(slideX.slideRight);

},

slideLeft: function () {

slideX._btnLeft.unbind('click', slideX.slideLeft);

for (i = 0; i 2; i++) {

slideX._this.find('li:last').prependTo(slideX._this);

}

slideX._this.css('marginLeft', -224);

slideX._this.animate({

'marginLeft': 0

},

500,

function () {

slideX._btnLeft.bind('click', slideX.slideLeft);

});

return false;

},

slideRight: function () {

slideX._btnRight.unbind('click', slideX.slideRight);

slideX._this.animate({

'marginLeft': -224

},

500,

function () {

slideX._this.css('marginLeft', '0');

for (i = 0; i 2; i++) {

slideX._this.find('li:first').appendTo(slideX._this)

}

slideX._btnRight.bind('click', slideX.slideRight);

});

return false;

}

}

$(document).ready(function () {

slideX.init();

})

$(document).ready(function () {

var newTime = new Date();

var newTime = newTime.getTime();

var $imgTmp = $('#topromotion').find('img:first');

var osrc = $imgTmp.attr('src');

$imgTmp.attr('src', osrc + '?' + newTime);

});

希望对你有帮助!

求一个图片轮换JS效果代码

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

style type="text/css"

* { margin:0; padding:0; word-break:break-all; }

ul, li { list-style:none; }

#focus_change_btn .current { background:url() no-repeat 37px 8px;}

#focus_change_btn .current img { border-color:#EEE; }

#focus_change_btn li { display:inline; float:right; margin:0 10px; padding-top:12px; }

#focus_change_btn li img { width:20px; height:20px; border:2px solid #888; }

#abb { width:200px; height:200px;}

#abb li { display:inline; margin:40px 20px; }

#abb li img { width:200px; height:50px; border:0;}

/style

script type="text/javascript"

function $(id) { return document.getElementById(id); }

/*位移算法,参数分别是:ID名,水平位移,垂直位移,和延迟时间(就是漂移时间);每次移动的距离加上一张图片的width或者height就行。*/

function moveElement(elementID,final_x,final_y,interval) {

if (!document.getElementById) return false;

if (!document.getElementById(elementID)) return false;

var elem = document.getElementById(elementID);

if (elem.movement) {

clearTimeout(elem.movement);

}

if (!elem.style.left) {

elem.style.left = "0px";

}

if (!elem.style.top) {

elem.style.top = "0px";

}

var xpos = parseInt(elem.style.left);

var ypos = parseInt(elem.style.top);

if (xpos == final_x ypos == final_y) {

return true;

}

if (xpos final_x) {

var dist = Math.ceil((final_x - xpos)/10);//ceil(x)对x进行上舍入

xpos = xpos + dist;

}

if (xpos final_x) {

var dist = Math.ceil((xpos - final_x)/10);

xpos = xpos - dist;

}

if (ypos final_y) {

var dist = Math.ceil((final_y - ypos)/10);

ypos = ypos + dist;

}

if (ypos final_y) {

var dist = Math.ceil((ypos - final_y)/10);

ypos = ypos - dist;

}

elem.style.left = xpos + "px";

elem.style.top = ypos + "px";

var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";

elem.movement = setTimeout(repeat,interval);

}

/*清除CSS,方便后面添加*/

function classNormal(){

var focusBtnList = $('focus_change_btn').getElementsByTagName('li');

for(var i=0; ifocusBtnList.length; i++) {

focusBtnList[i].className='';

}

}

/*修改下面的图片顺序*/

function changeAbb(i,j,k){

var abblist = $('abb').getElementsByTagName('img');

abblist[i].src='images/t1.gif';

abblist[j].src='images/t2.gif';

abblist[k].src='images/t3.gif';

}

/*给触发按钮添加事件*/

function focusChange() {

var focusBtnList = $('focus_change_btn').getElementsByTagName('li');

focusBtnList[0].onmouseover = function() {

moveElement('focus_change_list',0,0,5);

classNormal();

focusBtnList[0].className='current';

changeAbb(0,1,2);

}

focusBtnList[1].onmouseover = function() {

moveElement('focus_change_list',-250,0,5);

classNormal();

focusBtnList[1].className='current';

changeAbb(1,0,2);

}

focusBtnList[2].onmouseover = function() {

moveElement('focus_change_list',-500,0,5);

classNormal()

focusBtnList[2].className='current';

changeAbb(1,2,0);

}

}

window.onload=function(){

focusChange();

}

/script

/head

body

div style="width:410px;height:245px;position:relative;margin:0;padding:0; border:1px solid blue;"

div id="focus_change" style="position:relative; width:250px; height:245px; overflow:hidden; margin:0px 0px 0px 80px;"

div id="focus_change_list" style="top:0; left:0;position:absolute; width:760px; height:245px; "

ul

li style="float:left;" img style="width:250px; height:245px; border:none; " src=""/ /li

li style="float:left;"img style="width:250px; height:245px; border:none; " src=""/ /li

li style="float:left;"img style="width:250px; height:245px; border:none; " src=""/ /li

/ul

/div

/div

div style="position:absolute; width:410px; height:30px; top:200px; left:0; background:#000; filter:alpha(opacity=50); -moz-opacity:0.5; opacity: 0.5;"/div

div id="focus_change_btn" style="position:absolute; width:410px; height:60px; top:190px; left:0;"

ul style="padding-left:5px;"

li class="current"a href="#"img src="" alt="" //a/li

lia href="#"img src="" alt="" //a/li

lia href="#"img src="" alt="" //a/li

/ul

/div

/div

div

ul id="abb"

lia href="#"img src="" alt="" //a/li

lia href="#"img src="" alt="" //a/li

lia href="#"img src="" alt="" //a/li

/ul

/div

/body

/html

/*楼主的图片我看不清楚,我用百度中心的图替代一下。CSS改成自己需要的,我中间加了个遮蔽层,楼主觉得不好看可以删掉*/

Js图片轮播思路

a href=""js图片轮播效果代码/a

首先我们需要引入一张图片,通过更改img标签中src的值,达到图片切换功能。

html代码:img src="" width="331" height="220" id="carousel"

在这我们需要理理自己的思路,一、图片从何而来 二、怎么样使图片轮播,能够动起来

自定义一个数组,将需要的图片存在中间,代码如下:

var arr=new Array();

arr[0]='1.jpg';

arr[1]='2.jpg';

arr[2]='3.jpg';

arr[3]='4.jpg';

接着我们需要能够对图片进行操作定义一个函数,

function tImg(){var obj=document.getElementById('carousel');obj.src=''+arr[carIndex];}

准备好以后我们只需要获取数组的下标即可

定义初始化下标:var carIndex=0;

在函数中如果carIndex变量等于数组的字符串长度-1的情况下,赋给carIndex=0的初始数值。不是的情况下carIndex就+或者=1,代码如下:

function tImg(){

var obj=document.getElementById('carousel');

if(carIndex==arr.length-1){

carIndex=0;}

else{

carIndex+=1;}

obj.src=''+arr[carIndex];obj.onmouseover=function(){

}

逻辑关系理清楚后我们下一步就是使他们动起来,我们需要引入setInterval来控制函数的时间,代码如下:

var time=setInterval(tImg,3000);函数3秒执行一次

做到这里我们已经能过使图片进行切换了。

网页随机不重复显示定时自动更换图片代码

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312" /

title无标题文档/title

/head

SCRIPT language=JavaScript

!-- // BannerAD

var bannerAD=new Array();

var bannerADlink=new Array();

var adNum=0;

bannerAD[0]="我的文档/My Pictures/23.jpg";

bannerADlink[0]="#";

bannerAD[1]="我的文档/My Pictures/sy_p2.gif";

bannerADlink[1]="#";

bannerAD[2]="我的文档/My Pictures/sy_p3.gif";

bannerADlink[2]="#";

bannerAD[3]="我的文档/My Pictures/sy_p4.gif";

bannerADlink[3]="#";

bannerAD[4]="我的文档/My Pictures/sy_p5.gif";

bannerADlink[4]="#";

var preloadedimages=new Array();

for (i=0;ibannerAD.length;i++){

preloadedimages=new Image();

preloadedimages.src=bannerAD;

}

function setTransition(){

if (document.all){

bannerADrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);

bannerADrotator.filters.revealTrans.apply();

}

}

function playTransition(){

if (document.all)

bannerADrotator.filters.revealTrans.play()

}

function nextAd(){

if(adNumbannerAD.length-1)adNum++ ;

else adNum=0;

setTransition();

document.images.bannerADrotator.src=bannerAD[adNum];

playTransition();

theTimer=setTimeout("nextAd()", 3500);

}

function jump2url(){

jumpUrl=bannerADlink[adNum];

jumpTarget='_blank';

if (jumpUrl != ''){

if (jumpTarget != '')window.open(jumpUrl,jumpTarget);

else location.href=jumpUrl;

}

}

function displayStatusMsg() {

status=bannerADlink[adNum];

document.returnValue = true;

}

//--

/SCRIPT

body table width="319" border="0" cellspacing="0" cellpadding="0"

tr

td width="319" height="1600"IMG src="我的文档/My Pictures/4068262_4071.jpg" name=bannerADrotator width="363" height="555" border=0 style="FILTER: revealTrans(duration=3,transition=23)"SCRIPT language=JavaScriptnextAd()/SCRIPT/td

/tr

/table

/body

/html

这是每个图片变换的 一个接着一个下去的 没有重复 只有当你的图片全部播完了 再一次播放下去 没有停止的哦 至于图片你要多少你就添加多几个

bannerAD[1]="我的文档/My Pictures/sy_p2.gif"; 代码就好了

希望能够帮到你

关于图片自动轮换js代码和图片自动轮换js代码是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/11741.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载