文字走马灯 置顶显示

html-css010

文字走马灯 置顶显示,第1张

应用css实现走马灯置顶显示

超出显示

用到命令 text-overflow : clip | ellipsis 文本超出:截断|省略

但这一条命令是看不到效果的,需要另外两条命令配合使用,让文本能够溢出,第一个是强制一行内显示,white-space:nowrap;第二个是溢出内容隐藏,overflow:hidden

超出跑马等效果

老的前端开发人员对于marquee标签肯定不陌生,一个被淘汰的标签,被刚入门的新手所喜爱,因为能通过一个简单的标签做出动态的效果。但是在实际应用上的局限性和效果的过时,使这个标签退出历史舞台,大家纷纷改用js来实现无间断滚动等效果。

新的CSS3 marquee设置,可以说功能强大了很多,更加易操作,用简单的代码解决了js中比较纠结的字符长度判断等难题。强烈推荐大家使用。

对于这个属性的定义,W3C标准用法和webkit内核浏览器的支持用法并不相同,由于我们立足实战实用,所以这里只介绍好用的。可用的。

我们需要四句常用命令

overflow:-webkit-marquee//指定溢出时滚动。

-webkit-marquee-style:scroll | slide | alternate//跑马灯样式,分三种。

scroll,从一端滚动到另一端,内容完全滚入(消失)时重新开始。slide,从一端滚到另一端,内容接触到另一端后,立马重新开始。alternate,内容不跑到显示区域外,在里面来回碰壁反弹。这里主要用第一种。

-webkit-marquee-repetition:infinite | number// 跑马灯跑的次数,infinite 为无限多次,不结束。或者可以用正整数设置滚动的次数。

-webkit-marquee-direction:up | down | left | right//跑动的方向,这个要注意结合实际情况,即实际你操作的标签文本流溢出在哪个方向溢出。

-webkit-marquee-speed:slow | normal | fast//跑动的速度设置。

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"

什么怎么做

font-family: "YaHei Microsoft"/*设置字体*/

font-weight: bold/*字体加粗*/

font-size: 30px/*字体大小*/

letter-spacing: 1px/*字体间距*/

color: #000/*字体颜色*/

opacity: .5/*字体透明度*/

box-shadow: 0 0 10px #f00/*阴影,阴影颜色*/

就这样设置就好啦。