A jquery-based drop-down menu to change the background image and jquery background image

Source: Internet
Author: User

A jquery-based drop-down menu to change the background image and jquery background image

Today, we will introduce a jquery-based drop-down menu to change the background image. Click the image in the upper-right corner, select a background image from the drop-down list, and click the image to change to a background image. Below:

Download Online Preview source code

Implementation code.

Html code:

  <a href="#" class="but"></a>    <div id="hf">        <div class="con">                                    <div class="scroll">                <div class="scrollCon">                    <ul>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                        <li>                            </li>                    </ul>                </div>            </div>        </div>    </div>

Css3 code:

*        {            margin: 0px;            padding: 0px;        }        body        {            background: url('images/55.jpg');        }        .but        {            width: 50px;            height: 50px;            background: url('images/rtop_1.png');            display: block;            position: fixed;            top: 0px;            right: 0px;        }        .but:hover        {            background: url('images/rtop_2.png');        }        #hf        {            width: 100%;            height: 200px;            background: rgba(0,0,0,0.5);            display: none;        }        #hf .con        {            width: 1200px;            height: 200px;            margin: 0 auto;            position: relative;        }        #hf .con .left        {            position: absolute;            top: 70px;            left: 0px;            cursor: pointer;        }        #hf .con .right        {            position: absolute;            top: 70px;            right: 0px;            cursor: pointer;        }        #hf .con .scroll        {            width: 1080px;            height: 200px;            overflow: hidden;            margin: 0 auto;            position: relative;        }        #hf .con .scroll .scrollCon        {            width: 1000%;            height: 200px;            position: absolute;            left: 0px;            top: 0px;        }        .scroll .scrollCon ul li        {            list-style: none;            width: 240px;            height: 140px;            border: 3px solid #fff;            float: left;            margin-left: 12px;            margin-right: 12px;            margin-top: 20px;            cursor: pointer;        }

Js Code:

$ (". But"). click (function () {$ ("# hf"). slideToggle ("slow") ;}); <! -- Click to change the body chart --> $ (". scrollCon ul li "). click (function () {var simg = $ (this ). find ("img "). attr ("src"); var bimg = simg. replace (/-\ d */, ''); // find the name of the big Image Based on the thumbnail $ (" body ").css (" background ", "url (" + bimg + ")"); // url ("+ bimg +"), add variable method}); <! -- Click the button on the left --> var click_num = 0; // the initial number of clicks $ (". left "). click (function () {click_num ++; // click_num + 1 if (click_num> 2) {click_num = 0 ;}$ (". scrollCon "). animate ({left: click_num * (-1080)}, 300) ;}); $ (". right "). click (function () {click_num --; // click_num + 1 if (click_num <0) {click_num = 2 ;}$ (". scrollCon "). animate ({left: click_num * (-1080)}, 300 );});

Via: http://www.w2bc.com/Article/18733

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.