


Alternative accordion effect web page content switching code implemented by JS_javascript skills
The example in this article describes the alternative accordion effect web page content switching code implemented by JS. Share it with everyone for your reference. The details are as follows:
This is an alternative accordion effect based on One Piece. It uses three background images. Please follow the code to download it. See more writing ideas for similar special effects. It will help improve your JS programming level. helpful.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-sfq-web-cha-style-codes/
The specific code 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>海贼王</title> <style type="text/css"> body{margin:0px;padding:0px;overflow:hidden;background:#151515;} #box{width:710px;height:350px;padding:2px 0 2px 2px;margin:210px auto;background:#111;} #box ul{margin:0px;padding:0px;float:left;} #box li{width:75px;height:350px;float:left;display:inline;margin-right:2px;overflow:hidden;list-style-type:none;position:relative;} .pos1, .pos2, .pos3, .pos4, .pos5{width:75px;height:350px;float:left;text-decoration:none;} .pos1 span, .pos2 span, .pos3 span, .pos4 span, .pos5 span{width:75px;height:350px;float:left;top:0px;left:0px;filter:alpha(opacity=10);opacity:0.1;overflow:hidden;position:absolute; text-decoration:none;} .pos1 span.preview{background:url(images/bw.jpg) no-repeat;} .pos1 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat;} .pos2 span.preview{background:url(images/bw.jpg) no-repeat -75px 0;} .pos2 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -75px 0;} .pos3 span.preview{background:url(images/bw.jpg) no-repeat -152px 0;} .pos3 span.img_pre{left:75px;filter:alpha(opacity=100);opacity:1;background:url(images/color.jpg) no-repeat -152px 0;} .pos4 span.preview{background:url(images/bw.jpg) no-repeat -228px 0;} .pos4 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -228px 0;} .pos5 span.preview{background:url(images/bw.jpg) no-repeat -303px 0;} .pos5 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -303px 0;} .inner {width:280px;height:310px;float:left;padding:20px;background:#fff;overflow:hidden;border-right:5px solid #f0f0f0; position:absolute;top:0px;left:75px;} .inner h2{width:280px;height:60px;float:left;color:#555555;font-family:"微软雅黑";line-height:60px;font-size:18px;text-indent:10px;margin:0px;padding:0px;background:url(images/stripe_light.gif);} .inner h3{width:280px;height:40px;float:left;color:#fff;font-family:"微软雅黑";line-height:40px;font-size:14px;text-indent:10px;margin:0px;padding:0px;background:url(images/stripe.gif);} .inner p{width:260px;height:200px;float:left;color:#000;font-family:"微软雅黑";line-height:25px;font-size:12px;margin:0px;padding:0px 10px;} </style> <script type="text/javascript"> window.onload = function(){ var oBox = document.getElementById('box'); var aLi = oBox.getElementsByTagName('li'); var aA = oBox.getElementsByTagName('a'); var aPrev = getClass(oBox, 'preview'); var aImg = getClass(oBox, 'img_pre'); var i = 0; for(i=0;i<aA.length;i++){ aA[i].index = i; aA[i].onclick = function(){ for(i=0;i<aLi.length;i++){ if(aLi[this.index].style.width != '400px')startMove(aLi[i], {width:75}, 5); startMove(aPrev[i], {opacity:10}, 5); startMove(aImg[i], {opacity:0, left:75}, 5); } if(aLi[this.index].style.width != '400px'){ startMove(oBox, {width:710}, 5); startMove(aImg[this.index], {opacity:100, left:0}, 5); startMove(aLi[this.index], {width:400}, 5); }else{ startMove(aLi[this.index], {width:75}, 5); for(i=0;i<aLi.length;i++){ startMove(aPrev[i], {opacity:100}, 5); } startMove(oBox, {width:385}, 5); } }; } }; function getClass(oParent, sClass){ var aElem = oParent.getElementsByTagName('*'); var aClass = []; var i = 0; for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]); return aClass; } function startMove(obj, json, iT, fnEnd){ if(obj.timer)clearInterval(obj.timer); obj.timer = setInterval(function (){ doMove(obj, json, iT, fnEnd); }, 30); } function getStyle(obj, attr){ return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, false)[attr]; } function doMove(obj, json, iT, fnEnd){ var iCur = 0; var attr = ''; var bStop = true; for(attr in json){ attr == 'opacity' ? iCur = parseInt(100*parseFloat(getStyle(obj, 'opacity'))) : iCur = parseInt(getStyle(obj, attr)); if(isNaN(iCur))iCur = 0; var iSpeed = (json[attr]-iCur) / iT; iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); if(parseInt(json[attr])!=iCur)bStop = false; if(attr=='opacity'){ obj.style.filter = "alpha(opacity:"+(iCur+iSpeed)+")"; obj.style.opacity = (iCur + iSpeed) / 100; }else{ attr == 'zIndex' ? obj.style[attr] = iCur + iSpeed : obj.style[attr] = iCur + iSpeed +'px'; } } if(bStop){ clearInterval(obj.timer); obj.timer = null; if(fnEnd)fnEnd(); } } </script> </head> <body> <div id="box"> <li> <a href="javascript:;" class="pos1"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>乌索普</h2> <h3>草帽海贼团【狙击手】</h3> <p>悬赏:3000万(司法岛事件)</p> </div> </li> <li> <a href="javascript:;" class="pos2"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>罗罗诺亚·索隆</h2> <h3>草帽海贼团【剑士】</h3> <p>悬赏:6千万(阿拉巴斯坦事件)→1亿2000万(司法岛事件)</p> </div> </li> <li style="width:400px;"> <a href="javascript:;" class="pos3"> <span class="preview"></span> <span class="img_pre" style="left:0px;"></span> </a> <div class="inner"> <h2>蒙其·D·路飞</h2> <h3>草帽海贼团【船长】</h3> <p>恶魔果实:橡胶果实<br />悬赏:3千万(可可亚西村事件)→1亿(阿拉巴斯坦事件)→3亿(司法岛事件)→4亿(顶上战争后)</p> </div> </li> <li> <a href="javascript:;" class="pos4"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>娜美</h2> <h3>草帽海贼团【航海士】</h3> <p>悬赏:1600万(司法岛事件)</p> </div> </li> <li> <a href="javascript:;" class="pos5"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>香吉士</h2> <h3>草帽海贼团【厨师】</h3> <p>悬赏:7700万(司法岛事件)</p> </div> </li> </div> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

The browser cannot open the web page but the network is normal. There are many possible reasons. When this problem occurs, we need to investigate step by step to determine the specific cause and solve the problem. First, determine whether the webpage cannot be opened is limited to a specific browser or whether all browsers cannot open the webpage. If only one browser cannot open the web page, you can try to use other browsers, such as Google Chrome, Firefox, etc., for testing. If other browsers are able to open the page correctly, the problem is most likely with that specific browser, possibly

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

How to solve the problem of web pages not opening With the rapid development of the Internet, people increasingly rely on the Internet to obtain information, communicate and entertain. However, sometimes we encounter the problem that the web page cannot be opened, which brings us a lot of trouble. This article will introduce you to some common methods to help solve the problem of web pages not opening. First, we need to determine why the web page cannot be opened. Possible reasons include network problems, server problems, browser settings problems, etc. Here are some solutions: Check network connection: First, we need

Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.
