用JQUERY怎么做出来 图片从右到左自动切换,点击向右的标志,向右移动一张图片

html-css07

用JQUERY怎么做出来 图片从右到左自动切换,点击向右的标志,向右移动一张图片,第1张

这种插件非常多, 你可以挑一个用

如果你要问原理, 关键点是

外层div是一个窗口, 控制好长宽, 设置overflow为hidden, 那么只有在此区域内的内容才会被显示

内容是一堆图片, 通过js控制位置, 比如用relative定位, 通过css控制left, 就是移动效果

如果要轮播, 注意控制边界图片次序

CSS+DIV是网站标准(或称“WEB标准”)中常用的术语之一,通常为了说明与HTML网页设计语言中的表格(table)定位方式的区别,因为XHTML网站设计标准中,不再使用表格定位技术,而是采用css+div的方式实现各种定位。

CSS是英语Cascading Style Sheets(层叠样式表单)的缩写,它是一种用来表现 HTML 或 XML 等文件式样的计算机语言。

DIV元素是用来为HTML文档内大块(block-level)的内容提供结构和背景的元素。DIV的起始标签和结束标签之间的所有内容都是用来构成这个块的,其中所包含元素的特性由DIV标签的属性来控制,或者是通过使用样式表格式化这个块来进行控制。

<div id="mContainer"></div>

<input class="btn" id="pauseBtn" onclick="doPause()" type="button" value="pause" />

建立一个层,设置id为mContainer,作为图片的容器层。

设置一个按钮来控制图片切换的暂停与继续。

我们看下面的CSS代码:

#mContainer {

width:225px

position:relative

height:168px

}

.mPhoto {

filter:Alpha(opacity=0)

left:0px

position:absolute

top:0px

moz-opacity:0.0

}

.btn {

border-right:#000 1px solid

border-top:#000 1px solid

margin-top:5px

font-size:9px

border-left:#000 1px solid

width:40px

border-bottom:#000 1px solid

font-family:verdana

}

这些代码我们都能看明白,需要指出的是类mPhoto的样式定义。

主要是应用了滤镜将图片的透明度设置为零,完全透明。

我们看下面的javascript脚本:

var currentPhoto = 0

var secondPhoto = 1

var currentOpacity = new Array()

var imageArray = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg")

var FADE_STEP = 2

var FADE_INTERVAL = 10

var pause = false

function init() {

currentOpacity[0]=99

for(i=1i<imageArray.lengthi++)currentOpacity[i]=0

mHTML=""

for(i=0i<imageArray.lengthi++)mHTML+="<div id=\"photo\" name=\"photo\" class=\"mPhoto\"><img src=\"" + imageArray[i] +"\"></div>"

document.getElementById("mContainer").innerHTML = mHTML

if(document.all) {

document.getElementsByName("photo")[currentPhoto].style.filter="alpha(opacity=100)"

} else {

document.getElementsByName("photo")[currentPhoto].style.MozOpacity = .99

}

mInterval = setInterval("crossFade()",FADE_INTERVAL)

}

function crossFade() {

if(pause)return

currentOpacity[currentPhoto]-=FADE_STEP

currentOpacity[secondPhoto] += FADE_STEP

if(document.all) {

document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")"

document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")"

} else {

document.getElementsByName("photo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100

document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100

}

if(currentOpacity[secondPhoto]/100>=.98) {

currentPhoto = secondPhoto

secondPhoto++

if(secondPhoto == imageArray.length)secondPhoto=0

pause = true

xInterval = setTimeout("pause=false",2000)

}

}

function doPause() {

if(pause) {

pause = false

document.getElementById("pauseBtn").value = "pause"

把下面的代码直接复制过去,在下面注释的地方换成你的图片路径

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

.img{

width: expression(this.width >500 &&this.width >this.height ? 500 :true)

height: expression(this.height >500 ? 500 : true)

}

#marquee1 img{

width: expression(this.width >100 &&this.width >this.height ? 100 :true)

height: expression(this.height >100 ? 100 : true)

}

</style>

<script language="javascript">

function a(address)

{

var img1=document.getElementById("img1")

img1.src=address

}

</script>

</head>

<body>

<p> </p>

<p> </p>

<div style="width:800pxheight:100px" ><marquee width="800px" direction="left" scrollamount="20" id="marquee1" onmouseover="this.stop()" onmouseout="this.start()">

<img src="image/1.jpg" onclick="a(this.src)"/>//在这里改成你的小图片路径

<img src="image/2.jpg" onclick="a(this.src)"/>

<img src="image/3.jpg" onclick="a(this.src)"/>

<img src="image/4.jpg" onclick="a(this.src)"/>

<img src="image/5.jpg" onclick="a(this.src)"/>

<img src="image/6.jpg" onclick="a(this.src)"/>

</marquee>

</div>

<div style="text-align:centerheight:500px"><img id="img1" src="image/1.jpg" class="img"/></div>

</body>

</html>