JS to achieve FLASH slide image switching effect

  • 2020-05-10 17:46:01
  • OfStack

The example of this article describes the method of JS to realize FLASH slide picture switching effect. Share with you for your reference. The specific implementation method is as follows:

<!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" lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="gb2312" />
<meta name="author" content="RainoXu" />
<title>JS simulation FLASH Slide image toggle effect </title>
</head>
<body>
<style  type ="text/css">
/*  <![CDATA[  */
ul,li{
padding:0;
margin:0;
list-style:none;
}
#flashBox{
width:326px;
height:246px;
border:1px solid #EEE;
position:relative;
}
#flashBox img{
/* Don't show it initially */
display:none;
/* I'm going to use a border to make it empty, because margin and paading Sometimes it causes trouble */
border:3px solid #FFF;
}
#flashBox ul{
position:absolute;
right:7px;
bottom:9px;
font:9px tahoma;
}
#flashBox ul li{
display:block;
float:left;
width:12px;
height:12px;
line-height:12px;
margin-right:3px;
border:1px solid #999;
background:#F0F0F0;
text-align:center;
cursor:pointer;
}
#flashBox ul li.hover{
border-color:red;
background:#FFE1E1;
color:red;
}
/*  ]]>  */
</style>
<script type="text/javascript">
function flashBoxCtrl(o){
this.obj=document.getElementById(o);
// This private method is written, but it's not used yet
function addListener(ele,eventName,functionBody){
if (ele.attachEvent){
ele.attachEvent("on"+eventName, functionBody);
}else if (ele.addEventListener){
ele.addEventListener("on"+eventName,functionBody, false);
}else{
return false;
}
}
// Initialize the
this.init=function(){
var objImg=this.obj.getElementsByTagName("img");
var tagLength=objImg.length;
if (tagLength>0){
var oUl=document.createElement("ul");
oUl.setAttribute("id",o+"numTag");
for (var i=0;i<tagLength;i++){
var oLi=oUl.appendChild(document.createElement("li"));
if (i==0){
oLi.setAttribute("class","hover"); // Initialize when the first 1 I'm going to highlight
oLi.setAttribute("className","hover");
}
// Sets the number of the label
oLi.appendChild(document.createTextNode((i+1)));
}
this.obj.appendChild(oUl);
objImg[0].style.display="block";
// Set label events
var oTag=this.obj.getElementsByTagName("li");
for (var i=0;i<oTag.length;i++){
oTag[i].onmouseover=function(){
for (j=0;j<oTag.length;j++){
oTag[j].className="";
objImg[j].style.display="none";
}
this.className="hover";
objImg[this.innerHTML-1].style.display="block";
}
}
}
};
// The method for automatic scrolling hasn't been written yet
this.imgRoll=function(){};
// Automatically loads the generated object init() Method to initialize the object
this.init();
}
</script>
<div id="flashBox">
<img src="/images/m02.jpg" />
<img src="/images/m03.jpg" />
<img src="/images/m04.jpg" />
<img src="/images/m09.jpg" />
</div>
<script type="text/javascript">
// generate 1 An object
new flashBoxCtrl("flashBox");
</script>
</body>
</html>

I hope this article is helpful for you to design javascript program.


Related articles: