jquery to achieve the first page image fade effect method

Source: Internet
Author: User
Tags abs relative setinterval split lenovo

Here demo Dangdang Brand Shop Home Effect, demo address: http://static.dangdang.com/gm/topic/2270_181320.shtml

The effect diagram looks like this:

Demand:

1. Green area requirements above the picture, translucent display

2. When the mouse moves to the red area, toggle the corresponding picture

3. Homepage's three big picture rotation

Html:

1 2 3 4 5 6 7 8 9, <div id= "Carousel" > <div id= "carouselimg" class= "Content_top" > < Div id= "Imgcontainer" class= "Slide_panel" > <a target= "_blank" href= "http://www.baidu.com" mce_href= "http://" Www.baidu.com "></a> <a target= _blank" href= "http://www.google.com" mce_href= "http://www.google.com" >< /a> <a target= "_blank href=" http://www.dangdang.com "mce_href=" http://www.dangdang.com "></a> </div> </div> <div id= "Carouseltitle" > <ul> <li> <a href= "#" mce_href= "#" >, Lenovo <span>lenovo</span></a> </li> <li> <a href= "#" mce_href= "#" > Patriot <span >aigo</span></a> </li> <li> <a href= "#" mce_href= "#" > Clinique <span>clinique</ span></a> </li> </ul> </div>

Css:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 &lt;mce:style type= "Text/css" &gt;&lt;!--*{padding:0; margin:0} #carousel {border-color: #DFDFDF; border-style:solid ; border-width:0 1px 1px; Position:relative;/*do not deletes this line*/} #carousel ul{list-style:none;} #carousel #carouselimg {position:relative ;/*fix IE7 overflow bug*/Overflow:hidden; #carousel #carouselimg #imgcontainer {position:absolute; left:0px; top:0px} #carousel #carouselimg img{float:left;/* Fix IE6 auto-margin bug*/border:0; /*display:none;*/} #carousel #carouseltitle {position:absolute; bottom:0px} #carousel #carouseltitle ul{} #carousel #c Arouseltitle li{width:239px; height:30px; line-height:30px; font-size:14px; text-align:center; background: #000; color : #FFF; Float:left; Cursor:pointer; opacity:.6; Filter:alpha (opacity=60); #carousel #carouseltitle. active{background: #cfaf73; color: #FFF; opacity:.9 Filter:alpha (opacity=90);} #carousel # Carouseltitle. Active a{color: #000; #carousel #carouseltitle li a{text-decoration:none; color: #fff; #carousel #carouseltitle li a span{font-family:arial}--&gt;&lt;/mce:style&gt;&lt;style type= text/css "mce_bogus=" 1 "&gt; *{padding:0; margin:0} #carousel {border-color: #DFDFDF; border-style:solid;border-width:0 1px 1px; Position:relative;/*do not deletes this line*/} #carousel ul{list-style:none;} #carousel #carouselimg {position:relative ;/*fix IE7 overflow bug*/Overflow:hidden; #carousel #carouselimg #imgcontainer {position:absolute; left:0px; top:0px} #carousel #carouselimg img{float:left;/* Fix IE6 auto-margin bug*/border:0; /*display:none;*/} #carousel #carouseltitle {position:absolute; bottom:0px} #carousel #carouseltitle ul{} #carousel #c Arouseltitle li{width:239px; height:30px; line-height:30px; font-size:14px; text-align:center; background: #000; color : #FFF; Float:left; Cursor:pointer; opacity:.6; Filter:alpha (opacity=60); #carousel #carouseltitle. active{background: #cfaf73; color: #FFF; opacity:.9 Filter:alpha (opacity=90);} #carousel # Carouseltitle. ACtive a{color: #000; #carousel #carouseltitle li a{text-decoration:none; color: #fff;} #carousel #carouseltitle Li a spa n{font-family:arial; &lt;/style&gt;

Introducing the fr.carousel.js of River Zhang

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 The 96 97 98 99 100 101 102 103 104 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140-1 41 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170-171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201-2 02 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231-232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262-2 264 265 266 267 fr={Version: ' 1.0.0 ', Author: ' River Zhang (zhang_hechuan@hotmail.com) ', lisence: ' MIT lisence '}; FR. util={//replace document.getElementById. $:function (ID) {return document.getElementById (ID);},//replace getElementsByTagName. $$:function (node, tag) {return node.getelementsbytagname (tag);}, Creat:function (node,name) {var element= Document.createelement (name); Node.appendchild (Element); return element; },//event Binding functions. Addevent:function (eventtype,eventfunc,eventobj) {eventObj = EVENTOBJ | | document; if (window.attachevent) Eventobj.attachevent ("on" +eventtype,eventfunc); if (Window.addeventlistener) Eventobj.addeventlistener (Eventtype,eventfunc,false); }, Setopacity:function (obj, value) {if (document.all) Obj.style.filter = "Alpha (opacity=" + value + ")"; else OBJ.STYLE.O pacity = value/100; }, Setposition:function (obj, x, y) {var curx=parseint (obj.style.left); var cury=parseint (obj.style.top); if (isNaN )) curx=cury=0; var newx=curx+x; var newy=cury+y; Obj.style.left=newx+ ' px '; obj.style.top=newy+ ' px '; } }; FR. carousel={version: ' 1.1 ', mode:1, steps:20, period:25, width:300, height:200, bgcolor: ' #000000 ', autoswitch:true, delay : 5000, _semaphore:0,/* do don't try to modify this value */start:function (args) {if (typeof) args '!= ') {FR. carousel.mode=args.mode| | FR. Carousel.mode; FR. carousel.steps=args.steps| | FR. Carousel.steps; FR. carousel.period=args.period| | FR. Carousel.period; FR. carousel.width=args.width| | FR. Carousel.width; FR. carousel.height=args.height| | FR. Carousel.height; FR. carousel.bgcolor=args.bgcolor| | FR. Carousel.bgcolor; FR. carousel.autoswitch=args.autoswitch| | FR. Carousel.autoswitch; FR. carousel.delay=args.delay| | FR. Carousel.delay; } FR. Util.addevent ("Load", FR. Carousel.run,window); }, Run:function () {FR. Carousel.initialcss (); FR. Carousel.counter= ' frimg0 '; var carouselimg=fr.util.$ (' carouselimg '); var img=fr.util.$$ (carouselimg, ' img '); for (Var i=0;i!=img.length;++i) {img[i].id= ' frimg ' +i; if (FR. carousel.mode==4 | | FR. CAROUSEL.MODE==5) contInue; img[i].style.position= "Absolute"; img[i].style.left= "0 px"; img[i].style.top= "0 px"; FR. Util.setopacity (Img[i], 0); } if (FR. carousel.mode!=4) FR. Util.setopacity (Img[0], 100); if (FR. carousel.mode==1) bindfunction=function (name) {FR. Carousel.fade (fr.util.$ (name), FR. Carousel.steps, FR. Carousel.period);}; else if (FR. carousel.mode==2) bindfunction=function (name) {FR. Carousel.flash (fr.util.$ (name), FR. Carousel.steps, FR. Carousel.period);}; else if (FR. carousel.mode==3) bindfunction=function (name) {FR. Carousel.fadeintocolor (fr.util.$ (name), FR. Carousel.steps, FR. Carousel.period);}; else if (FR. carousel.mode==4) bindfunction=function (name) {FR. Carousel.scroll (name, FR. Carousel.steps, FR. Carousel.period);}; else if (FR. carousel.mode==5) bindfunction=function (name) {FR. Carousel.crawl (name, FR. Carousel.steps, FR. Carousel.period);}; var carouseltitle=fr.util.$ (' Carouseltitle '); var li=fr.util.$$ (carouseltitle, ' Li '); Li[0].classname= ' #carousel #carouseltitle active '; FR. Carousel.autocarousel (Img.leNgth); for (Var i=0;i!=li.length;++i) {(function () {var name= ' frimg ' +i; Li[i].onmouseover=function () {clearinterval () (FR. CAROUSEL.S); if (!FR. Carousel._semaphore) {Li[fr. Carousel.counter.split (') [FR. Carousel.counter.length-1]].classname= '; This.classname= ' #carousel #carouseltitle active '; Bindfunction (name); } }; Li[i].onmouseout=function () {FR. Carousel.autocarousel (img.length); } })(); }, Autocarousel:function (length) {if (FR. Carousel.autoswitch) {FR. Carousel.s=setinterval (function () {var carouseltitle=fr.util.$ (' Carouseltitle '); var li=fr.util.$$ (Carouseltitle, ' Li '); Li[fr. Carousel.counter.split (') [FR. Carousel.counter.length-1]].classname= '; var next= (parseint) (FR. Carousel.counter.split (') [FR. CAROUSEL.COUNTER.LENGTH-1]) +1%length; Li[next].classname= ' #carousel #carouseltitle active '; Name= ' frimg ' +next; Bindfunction (name); },fr. Carousel.delay); }, Initialcss:function () {var carouselimg=fr.util.$ (' carouselimg '); var carousel=fr.util.$ (' Carousel '); Carouselimg.style.width=fr. Carousel.width+ "px"; Carouselimg.style.height=fr. carousel.height+ "px"; Carousel.style.width=fr. carousel.width+ "px"; Carousel.style.height=fr. carousel.height+ "px"; if (FR. carousel.mode==5) {var imgcontainer=fr.util.$ (' Imgcontainer '); var img=fr.util.$$ (carouselimg, ' img '); var size= Img.length*fr. Carousel.width; imgcontainer.style.width=size+ "px"; }, Fade:function (obj, steps, speed) {FR. carousel._semaphore=1; var value1=0; var value2=100; if (obj.id!=fr. Carousel.counter) {var carouselimg=fr.util.$ (' carouselimg '); var img=fr.util.$$ (carouselimg, ' img '); for (Var i=0;i!= Img.length;++i) {if (I!=FR). Carousel.counter.split (') [FR. CAROUSEL.COUNTER.LENGTH-1]) FR. Util.setopacity (Img[i], 0); } temp=fr. Carousel.counter; FR. Carousel.counter=obj.id; tempobj=fr.util.$ (temp); var increment=100/steps; FR. Carousel.i=setinterval (function () {if (value1&lt;=100) {FR. Util.setopacity (obj,value1); FR. Util.setopacity (tempobj,value2); Value1+=increment; Value2-=increment; else {clearinterval (FR. CAROUSEL.I); FR. Carousel._semaphore=0; }},speed); }else {FR. carousel._semaphore=0; Return }, Flash:function (obj, steps, speed) {FR. carousel._semaphore=1; var value1=0; if (obj.id!=fr. Carousel.counter) {var carouselimg=fr.util.$ (' carouselimg '); var img=fr.util.$$ (carouselimg, ' img '); for (Var i=0;i!= Img.length;++i) {FR. Util.setopacity (Img[i], 0); } FR. Carousel.counter=obj.id; var increment=100/steps; FR. Carousel.i=setinterval (function () {if (value1&lt;=100) {FR. Util.setopacity (obj,value1); Value1+=increment; else {clearinterval (FR. CAROUSEL.I); FR. carousel._semaphore=0; }},speed); }else {FR. carousel._semaphore=0; Return }, Fadeintocolor:function (obj, steps, speed) {FR. carousel._semaphore=1; var value1=100; var value2=0; if (obj.id!=fr. Carousel.counter) {var carouselimg=fr.util.$ (' carouselimg '); carouselimg.style.backgroundcolor=fr. Carousel.bgcolor; var img=fr.util.$$ (carouselimg, ' img '); for (Var i=0;i!=img.length;++i) {if (I!=FR). Carousel.counter.split (') [FR. CAROUSEL.COUNTER.LENGTH-1]) FR. Util.setopacity (Img[i], 0); } temp=fr. Carousel.counter; FR. Carousel.counter=obj.id; tempobj=fr.util.$ (temp); var increment=100/steps; FR. Carousel.i=setinterval (function () {if (value1&gt;=0) {FR. Util.setopacity (tempobj,value1); Value1-=increment; else if (value1&lt;0 &amp;&amp; value2&lt;=100) {FR. Util.setopacity (obj,value2); Value2+=increment; else {clearinterval (FR. CAROUSEL.I); FR. carousel._semaphore=0; }},speed); else {FR. carousel._semaphore=0; Return }, Scroll:function (Curno, steps, Speed) {FR. carousel._semaphore=1; var ic=fr.util.$ (' Imgcontainer '); var count= (Curno.split (') [CURNO.LENGTH-1]-FR. Carousel.counter.split (') [FR. CAROUSEL.COUNTER.LENGTH-1]) *fr. Carousel.height; FR. Carousel.counter=curno; var value1=0; var increment=count/steps; FR. Carousel.i=setinterval (function () {if (Math.Abs (value1) &lt;math.abs (count) {if (count&gt;0) {FR. Util.setposition (ic,0,-increment); Value1-=increment; } else{FR. Util.setposition (ic,0,-increment); Value1+=increment; } else {clearinterval (FR. CarousEL.I); FR. carousel._semaphore=0; }},speed); }, Crawl:function (Curno, steps, Speed) {FR. carousel._semaphore=1; var ic=fr.util.$ (' Imgcontainer '); var count= (Curno.split (') [CURNO.LENGTH-1]-FR. Carousel.counter.split (') [FR. CAROUSEL.COUNTER.LENGTH-1]) *fr. Carousel.width; FR. Carousel.counter=curno; var value1=0; var increment=count/steps; FR. Carousel.i=setinterval (function () {if (Math.Abs (value1) &lt;math.abs (count) {if (count&gt;0) {FR. Util.setposition (ic,-increment,0); Value1-=increment; } else{FR. Util.setposition (ic,-increment,0); Value1+=increment; } else {clearinterval (FR. CAROUSEL.I); FR. carousel._semaphore=0; }},speed); } };

can achieve the rotation effect of the picture, but click on the picture, each link jump is the last picture of a href

View Fr.carousel.js, it turns out, it realizes the idea is to three pictures of a stack on top of a piece, using setinterval (), the opacity value of a map to 1, the remaining two for 0. However, this will cause you to click on the image, each link is the top of the picture (that is, the last Clinique that one).

Workaround:

Set the z-index of the rotation chart, when the picture is displayed, its parent node <a> Z-index is higher than other elements.

jquery implementation:

1 2 3 4 5 6 7 8 9 10 11 12 13-14 To determine the IMG rotation, implement a Jump SetInterval (function () {$ ("#imgcontainer a"). each (function (i) {var img = $ (this). Children ("img"); var OP = img.css ("opacity"); if (op>0) {img.css ("Z-index", "M"); $ (this). CSS ("Z-index", "100");} else{img.css ("Z-index", "0"); $ (this). CSS ("Z-index", "0");}}) },100);

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.