JQ slide slides

Source: Internet
Author: User

The code for the JQ slide slides that have been found online for a long time is highly handwritten.
It's easy to change a lot of parameters.

This is what I wrote myself. I mainly practiced the usage of several functions.

HTML section:

<div class="silde">    <ul class="container">        <li></li>            <li></li>            <li></li>            <li></li>            <li></li>        </ul>        <div class="index">        <ul>            <li><a href="#">1</a></li>                <li><a href="#">2</a></li>                <li><a href="#">3</a></li>                <li><a href="#">4</a></li>                <li><a href="#">5</a></li>            </ul>        </div>    </div>

CSS section:

.silde{width:960px; height:200px; overflow:hidden; display:block; border:1px #999 dashed; margin-top:100px; float:left;}.silde .container{width:5050px; height:auto; position:relative;}.silde ul{list-style:none;}.silde ul li{float:left; width:960px; text-align:center;}.silde .index{width:200px; height:30px; margin-right:5px; position:absolute; left:1000px; top:100px;}.index li{list-style:none; float:left;}.index li a{background:#CCCCCC; width:100px; height:20px; float:left; text-align:center; margin:10px; display:block; opacity:0.5; text-decoration:none; color:#FFF;}.index li a:hover{background:#FC3; float:left;}

JQ section:

 var ifmove=false;var setleft=0;var CN=1;var PN=1;var speed=0;var setoffmove=0;var T=null;var lock=false;function moveleft(){    try{        if(ifmove==true){            setleft-=speed;            setoffmove-=speed;            $(".container").css("left",setleft);            if(setoffmove<=0){                lock=false;                ifmove=false;                }            T=window.setTimeout("moveleft()",10);        }    }catch(e){        alert(e);    }};function moveright(){    try{        if(ifmove==true){            setleft+=speed;            setoffmove-=speed;            $(".container").css("left",setleft);            if(setoffmove<=0){                lock=false;                ifmove=false;            }            T=window.setTimeout("moveright()",10);        }    }catch(e){        alert(e);    }};$(document).ready(function(e) {    $("li").click(function(){        if(lock==false){            lock=true;            CN=$(this).find("a").html();            if(CN>PN){                setoffmove=(CN-PN)*960;                ifmove=true;                speed=10;                PN=CN;                    moveleft();            }else if(CN<PN){                setoffmove=(PN-CN)*960;                ifmove=true;                speed=10;                PN=CN;                moveright();            }        }        return false;    });});

PS:

Div cannot use position: absolute. You should use position: relative. You didn't pay attention to it for a long time at the beginning ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.