search
HomeWeb Front-endJS TutorialTeach you how to write a JD elevator carousel

Effect knowledge points: enterprise layout skills, how to write CSS styles efficiently, commonly used selectors, basic tags, box models, jquery class library calls, JS special effects writing, JS programming thinking, etc.

Jingdong elevator carousel source code:


<!doctype html>
<htmllang="en">
<head>
<!--网站编码格式,UTF-8 国际编码,GBK或 gb2312 中文编码-->
<metacharset="UTF-8">
<metaname="Keywords"content="关键词一,关键词二">
<metaname="Description"content="网站描述内容">
<title>Document</title>
<!--引用css js 文件的引入-->
<styletype="text/css">
*{margin:0px;}
/* 属性:值; 身高:1.7m; 颜色:红色; px像素*/
#flash{width:670px;/*宽*/height:240px;/*高*/background:#cc99cc;/*背景颜色*/
        margin:200pxauto 0px;
        position:relative;/*相对定位*/overflow:hidden;/*超出部分隐藏*/}
#flash .scroll{width:670px;height:2400px;
                position:absolute;/*绝对定位*/left:0px;top:0px;}
#flash .scroll img{display:block;/*块级*/}
#flash ul.button{height:20px;width:144px;position:absolute;
                bottom:20px;right:10px;}
#flash ul.button li{list-style-type:none;/*去掉圆点*/
        width:20px;height:20px;background:#666;float:left;/*左浮动*/
        margin:0px2px;
        color:#fff;text-align:center;/*水平距中*/
        font-size:12px;
        line-height:20px;/*行高 文字竖直距中*/
        border-radius:10px;/*圆半径*/
        box-shadow:2px2px 5px #000; }
#flash ul.button li.hover{background:#cc3300;}
</style>
</head>
<body>
<!--p 盒子模型,高度,宽度,放内容的长方形容器 姓名=“张三”-->
<pid="flash">
    <!--图片滚动开始-->
    <pclass="scroll">
        <img  src="/static/imghwm/default1.png"  data-src="images/1.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
        <img  src="/static/imghwm/default1.png"  data-src="images/2.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
        <img  src="/static/imghwm/default1.png"  data-src="images/3.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
        <img  src="/static/imghwm/default1.png"  data-src="images/4.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
        <img  src="/static/imghwm/default1.png"  data-src="images/5.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
        <img  src="/static/imghwm/default1.png"  data-src="images/6.jpg"  class="lazy" / alt="Teach you how to write a JD elevator carousel" >
    </p>
    <!--图片滚动结束-->
    <!--按扭开始-->
    <ulclass="button">
        <liclass="hover">1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
    </ul>
    <!--按扭结束-->
</p>
<!--引用 jqeury 文件-->
<scripttype="text/javascript"src="js/jquery.js"></script>
<scripttype="text/javascript">
    var_index=0;
    varsetTime=null;
    $("ul.button li").hover(function(){
        clearInterval(setTime);//清处定时播放器
        _index=$(this).index();
        //alert(_index);
        // 给添加 class="hover"
        $(this).addClass("hover").siblings("li").removeClass("hover");
        $(".scroll").animate({top:-(_index*240)},1000);
    },function(){
        autoPlay();//鼠标移开,调用自动播放
    });
    //自动轮播
    functionautoPlay(){
        setTime=setInterval(function(){
            _index++;//序列号加 1
            if(_index>5){_index=0;}//当播到最后一张时,回到第一张
            $("ul.button li").eq(_index).addClass("hover").siblings("li").removeClass("hover");
            $(".scroll").animate({top:-(_index*240)},1000);
        },2000);
        
    }
    autoPlay();
</script>
<!--
    1、如何在页面当中构建一个有宽度,高度的长方形 (p盒子模型)
    2、讲到了外边距的概念 margin, 解决了外边距的兼容型问题 *{margin:0px;}
    3、利用外边距来控制长方形的位置 margin:上(200px) 左右(auto) 下(0px);
    4、分析了动画实现原理(在 #flash)长方形里,构建了一个宽度一样大小,高度无限高的长方      形) 然后利用相对和绝对定位来实现他的动画原理
    5、如何在页面当中插入一张图 <img  src="/static/imghwm/default1.png"  data-src="地址"  class="lazy"  / alt="Teach you how to write a JD elevator carousel" >
    6、处理了图片之间产生间隙的问题(display:block;) 超出部分内容隐藏 overflow:hidden;
    7、讲ul无序列表标签 (去掉li的圆点,给li添加宽度和高度 利用把小长方形从竖直变成水平      控制文字大小,颜色 水平距中,竖直距中,利最新技术css3 把正方形变成圆形              border-radius:10px; 利用外边距产生兼距)
-->
</body>
</html>

Finally give the program Some suggestions from members:

1. There is no so-called "best language" Some languages ​​and tools are only used to solve specific corresponding problems. A little better than others. When learning a new language, don't try to bring your past thought patterns into the new language system. Accordingly, we should learn how to program in a new language more "authentically".

2. Relax and stay "simple" Programming is a huge collection of Lego bricks, full of All kinds of interesting problems that need to be solved. Taking the time to write interesting programs in order to deeply understand the structure will be more interesting than any appointment given to you.

3. The best programmers always try programming outside of work. If you really love it and are good at it, you will never be unemployed.

4. When you get stuck, write down your program on paper. I was serious. This is amazing and is the standard training pattern in programming competitions. (The reason I think this works is that when you don't have to spend energy thinking about syntax, you have more energy thinking about the nature of the problem and how to solve it).

The above is the detailed content of Teach you how to write a JD elevator carousel. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor