JQUERY+CSS Realization of Mobile Web page bullet-window Touch-screen Photo Album example attached source code

Source: Internet
Author: User
Tags abs bind pow touch

Today, we have to introduce a touch screen effect, we used to browse the site details page, often see such an effect, when you click on a picture, you will be the other pictures in the window mode display, and then, you can go up and down the button to achieve the picture switch.

So, how do you do that on your phone?

I lined up a group of small graphs, and when I clicked, I put the picture in the ID IMGs through jquery, and then, by positioning technology, I showed the picture:

On the click of which picture of the effect, I was through the above code to achieve, and then, the user can achieve left and right switch, we also added a count on the function.

Here, we use the TouchSwipe script, we use this script, we can implement simple swipe function. You can take a look at this site first: http://labs.skinkers.com/touchSwipe/

This kind of jquery-like notation allows us to implement some simple swipe functions,

But I always felt that there was a place in this work, not perfect, when I use vertical screen display photos, and then turn to horizontal screen, the result width can not be automatically updated, so that the effect is not perfect, the user only click on the Refresh button, window-like album to return to Normal, and then the day, we together to improve him.

Index.html Code

The code is as follows Copy Code
<! DOCTYPE html>


<html>


<head>


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">


<meta name= "viewport" content= "Width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, User-scalable=no ">


<script type= "Text/javascript" src= "Https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" >< /script>


<script type= "Text/javascript" src= "Js/jquery.touchswipe.min.js" ></script>


<title> touch screen effects, mobile Web </title>


<link href= "Css/css.css" Type=text/css rel=stylesheet>


</head>


<body>


<div class= "BG" ></div>


<b class= "Close" > Shutdown </b>


<span class= "S_count" ><i></i>/<em></em></span>


<ul class= "S_ul" >


<li><img src= "Images/img01.jpg" ></li>


<li><img src= "Images/img02.jpg" ></li>


<li><img src= "Images/img03.jpg" ></li>


<li><img src= "Images/img04.jpg" ></li>


<li><img src= "Images/img01.jpg" ></li>


<li><img src= "Images/img02.jpg" ></li>


<li><img src= "Images/img03.jpg" ></li>


<li><img src= "Images/img04.jpg" ></li>


</ul>


<div id= "Content" >


<ul id= "IMGs" >





</ul>


</div>


<script>


$ ('. S_ul li '). Click (function () {


$ (' #content '). Show ();


$ ('. BG '). Show ();


$ ('. Close '). Show ();


$ ('. S_count '). Show ();


$ (' #imgs '). Show ();


$ (this). Parent (). Find (' Li '). Clone (). Appendto (' #imgs ');


var n=$ ("#imgs li"). length;


var dw=100*n;


var fw=dw/64;


var fww=fw+ "%";


var dww=dw+ "%";


var ll=$ ("#imgs li"). Width (FWW);


var i=$ (this). index () +1;


$ ('. S_count em '). Text (n);


var left=-100* (i-1) + "%";


var fq=0;


$ ('. S_count i '). text (i);


$ ("#imgs li"). CSS ("-webkit-transform", "Translate3d" ("+left+", 0px,0px));


$ (' #imgs '). Width (DWW);


var img_width =100+ "%";


$ ("#imgs Li"). Swipe ({


Swipeleft:function () {


var d=$ (this). index ();


d=d+1;


i=i+1;


Fq=100*d;


left=-fq+ "%";


if (d==8) {


Alert (' last picture ');


i=8;


}else{


$ ("#imgs li"). CSS ({"-webkit-transform": "Translate3d" ("+left+", 0px,0px) ","-webkit-transition ":" 500ms Linear "});


}


$ ('. S_count i '). text (i);





},


Swiperight:function () {


var d=$ (this). index ();


D=d-1;


I=i-1;


Fq=-100*d;


left=fq+ "%";


if (d==-1) {


Alert (' first one ');


I=1;


}else{


$ ("#imgs li"). CSS ({"-webkit-transform": "Translate3d" ("+left+", 0px,0px) ","-webkit-transition ":" 500ms Linear "});


}


$ ('. S_count i '). text (i);





}


});











});


$ ('. Close '). Click (function () {


$ ('. BG '). Hide ();


$ ('. Close '). Hide ();


$ ('. S_count '). Hide ();


$ (' #content '). Hide ();


$ (' #imgs li '). Remove ();


})


</script>


</body>


</html>


CSS.CSS Code

The code is as follows Copy Code
@charset "Utf-8";


article,aside,details,figcaption,figure,footer,header,hgroup,nav,section {display:block;}


Html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,form,fieldset,legend,input,lable,textarea,p,blockquote,th,td {margin:0;padding:0;}


html{font-size:100%;overflow-y:scroll;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; height:100%;}


table{border-collapse:collapse;border-spacing:0;}


fieldset,img{border:0;}


Address,caption,cite,code,dfn,em,th,var{font-style:normal; font-weight:normal;}


Ol,ul{list-style:none;}


h1,h2,h3,h4,h5,h6{font-weight:normal;font-size:100%;}


body{height:100%;}





body{position:relative; width:100%;}


#content {display:none;width:100%;overflow:hidden;position:absolute; top:15%; height:100%;}


#imgs {-webkit-transition-property:-webkit-transform;-webkit-transition-duration:0.5s;


-webkit-transition-timing-function:ease-out;padding:0px;margin:0px;-webkit-transform:translate3d (0px,0px,0px); top:0;}


#imgs li{Float:left;text-align:center;}


#imgs Img{width:90%;-webkit-transform:translate3d (0px,0px,0px);


. s_ul{width:100%; float:left; padding-top:20px;}


. S_ul li{float:left; margin-left:10px; width:90px; height:80px; overflow:hidden;


. s_ul Li img{width:90px; list-style:none;}


. bg{width:100% height:200% background: #000; opacity:0.6; position:absolute; display:none;}


close{display:none; Position:absolute z-index:10; right:20px; top:20px; color: #fff; cursor:pointer;


s_count{display:none; Position:absolute z-index:10; right:80px; top:20px; color: #fff;}

Jquery.touchSwipe.min.js Code

The code is as follows Copy Code
(function (d) {var l= ' left ', k= ' right ', c= ' up ', r= ' down ', b= ' in ', s= ' out ', i= ' none ', o= "Auto", u= "horizontal", p= "vertical" , f= "All", e= "Start", h= "move", g= ' End ', m= "Cancel", a= "Ontouchstart" in window,t= "TouchSwipe"; var j={fingers:1, Threshold:75,maxtimethreshold:null,swipe:null,swipeleft:null,swiperight:null,swipeup:null,swipedown:null, Swipestatus:null,pinchin:null,pinchout:null,pinchstatus:null,click:null,triggerontouchend:true,allowpagescroll : "Auto", fallbacktomouseevents:true,excludedelements: "button, input, select, textarea, a,. noswipe"};d. fn.swipe= function (x) {var w=d (this), V=w.data (t), if (v&&typeof x=== "string") {if (v[x)) {return v[x].apply Array.prototype.slice.call (arguments,1))}else{d.error ("method" +x+ "does not exist on Jquery.swipe")}}else{if (!v && (typeof x=== "Object" | |! x)) {return q.apply (this,arguments)}}return W};d. Fn.swipe.defaults=j;d.fn.swipe.phases={phase_start:e,phase_move: H,PHASE_END:G,PHASE_CANCEL:M};d. fn.swipe.directions={left:l,right:k,up:c,down:r,in:b,out:s};d.Fn.swipe.pagescroll={none:i,horizontal:u,vertical:p,auto:o};d. Fn.swipe.fingers={one:1,two:2,three:3,all:f}; function Q (v) {if (v&& v.allowpagescroll===undefined&& v.swipe!==undefined| | v.swipestatus!==undefined))) {v.allowpagescroll=i}if (!v) {v={}}v=d.extend ({},d.fn.swipe.defaults,v); This.each (function () {var x=d (this); var w=x.data (t); if (!w) {w=new n (this,v); X.data (T,w)}})}function N (j,r) {var aj= (a| |! r.fallbacktomouseevents), Ae=aj? " Touchstart ":" MouseDown ", K=aj?" Touchmove ":" MouseMove ", Ac=aj?" Touchend ":" MouseUp ", i=" Touchcancel "; var p=0;var e=null;var s=0;var af=0;var w=0;var u=1;var ak=0;var A=d (J); var F=" Start "; var ai=0;var t=null;var B=0;var M=0;try{a.bind (AE,AA); A.bind (i,d)}catch (AG) {d.error ("Events not supported" +ae+ "," +i+ "on Jquery.swipe")}this.enable=function () {A.bind (AE , AA); A.bind (i,d); return a};this.disable=function () {h (); return a};this.destroy=function () {h (); A.data (t,null); return a};function AA (AO) {if (L)) {return}if (d (Ao.target). Closest (R.excludedelements,a). Length>0) {Return}var Ap=ao.originalevent;var An,am=a?ap.touches[0]:ap; F=e;if (a) {Ai=ap.touches.length}else{ao.preventdefault ()}p=0; E=null;ak=null; s=0;af=0;w=0; U=1; T=al (); if (!a| | (ai===r.fingers| | R.FINGERS===F) | | W ()) {T[0].start.x=t[0].end.x=am.pagex; T[0].start.y=t[0].end.y=am.pagey; B=x (); if (ai==2) {T[1].start.x=t[1].end.x=ap.touches[1].pagex; T[1].start.y=t[1].end.y=ap.touches[1].pagey;af=w=n (T[0].start,t[1].start)}if (r.swipestatus| | R.pinchstatus) {An=ah (AP,F)}}else{d (AP) an=false}if (An===false) {F=m;ah (ap,f); return An}else{v (TRUE); A.bind (K,G); A.bind (Ac,o)}}function G (AO) {var aq=ao.originalevent;if (f===g| | f===m) {Return}var an,am=a?aq.touches[0]:aq; T[0].end.x=a?aq.touches[0].pagex:am.pagex; T[0].end.y=a?aq.touches[0].pagey:am.pagey; M=x (); E=z (T[0].start,t[0].end); if (a) {ai=aq.touches.length}f=h;if (ai==2) {if (af==0) {T[1].start.x=aq.touches[1].pagex; T[1].start.y=aq.touches[1].pagey;af=w=n (T[0].start,t[1].start)}else{t[1].end.x=aq.touches[1].pagex; T[1].end.y=aq.touches[1].pagey;w=n (T[0].end,t[1].end); Ak=x (T[0].end,t[1].end)}u=v (af,w)}if (ai===r.fingers| | R.FINGERS===F) | |! A) {Y (ao,e); P=z (T[0].start,t[0].end); S=c (T[0].start,t[0].end); if (r.swipestatus| | R.pinchstatus) {An=ah (aq,f)}if (! R.triggerontouchend) {var ap=! Y (); if (Q () ===true) {F=g;an=ah (AQ,F)}else{if (AP) {F=m;ah (aq,f)}}}}else{f=m;ah (aq,f)}if (an===false) {F=m;ah (Aq,F)}} function O (AO) {var au=ao.originalevent;if (au.touches&&au.touches.length>0) {return true} Ao.preventdefault (); M=x (); if (af!=0) {w=n (t[0].end,t[1].end); U=v (af,w); Ak=x (t[0].end,t[1].end)}p=z (t[0].start,t[0].end); E=z (T[0].start,t[0].end); S=c (); if (r.triggerontouchend| | (r.triggerontouchend===false&&f===h)) {F=g;var Aq=ad () | |! W (); var an= (ai===r.fingers| | R.FINGERS===F) | |! a); var am=t[0].end.x!==0;var ap= (An&&am&&aq); if (AP) {var ar=y (); var at=q (); if (at===true| | At===null) &&ar {AH (au,f)}else{if (!ar| | At===false) {F=m;ah (au,f)}}}else{f=m;ah (au,f)}}else{if (f===h) {F=m;ah (au,f)}}a.unbind (K,g,false); A.unbind (Ac,o,false); V (False)}function D () {ai=0; m=0;b=0;af=0;w=0; U=1; V (false)}function AH (ao,am) {var an=undefined;if (r.swipestatus) {An=r.swipestatus.call (a,ao,am,e| | null,p| | 0,s| | 0,ai)}if (R.pinchstatus&&ad ()) {An=r.pinchstatus.call (a,ao,am,ak| | null,w| | 0,s| | 0,ai,u)}if (am===m) {if r.click&& (ai===1| |! A) && (isNaN (P) | | p===0)) {An=r.click.call (a,ao,ao.target)}}if (am==g) {if (r.swipe) {an=r.swipe.call (A,ao,e,p,s,ai)}switch (E) {case L: if (r.swipeleft) {an=r.swipeleft.call (A,ao,e,p,s,ai)}break;case k:if (r.swiperight) {An=r.swiperight.call (A,ao,E,P, S,ai)}break;case c:if (r.swipeup) {an=r.swipeup.call (A,ao,e,p,s,ai)}break;case r:if (r.swipedown) {an= R.swipedown.call (A,ao,e,p,s,ai)}break}switch (AK) {case B:if (R.pinchin) {An=r.pinchin.call (a,ao,ak| | null,w| | 0,s| | 0,ai,u)}break;case s:if (r.pinchout) {An=r.pinchout.call (a,ao,ak| | null,w| | 0,s| | 0,ai,u)}break}}if (am===m| | AM===G) {D (AO)}return an}function Q () {if (r.threshold!==null) {return p>=r.threshold}return null}function Y () {var am ; if (r.maxtimethreshold) {if (s>=r.maxtimethreshold) {Am=false}else{aM=true}}else{am=true}return am}function y (am,an) {if (r.allowpagescroll===i| | W ()) {Am.preventdefault ()}else{var Ao=r.allowpagescroll===o;switch (a) {case l:if (R.swipeleft&&ao) | | (!ao&&r.allowpagescroll!=u)) {Am.preventdefault ()}break;case k:if (R.swiperight&&ao) | | (!ao&&r.allowpagescroll!=u)) {Am.preventdefault ()}break;case c:if (R.swipeup&&ao) | | (!ao&&r.allowpagescroll!=p)) {Am.preventdefault ()}break;case r:if (R.swipedown&&ao) | | (!ao&&r.allowpagescroll!=p)) {Am.preventdefault ()}break}}}function C () {return m-b}function N (Ap,ao) {var an=math.abs (ap.x-ao.x); var am=math.abs ( AP.Y-AO.Y); return Math.Round (Math.sqrt (an*an+am*am))}function V (am,an) {var ao= (an/am) *1;return ao.tofixed (2)} function X () {if (u<1) {return s}else{return b}}function Z (an,am) {return Math.Round (math.sqrt (MATH.POW) +math.pow (am.y-an.y,2))}function AB (Ap,an) {var am=ap.x-an.x;var ar=an.y-ap.y;var ao=math.atan2 (ar,am); var aq= Math.Round (AO*180/MATH.PI); if (aq< 0) {Aq=360-math.abs (aq)}return aq}function Z (an,am) {var ao=ab (an,am); if ((ao<=45) && (ao>=0)) {return L} Else{if ((ao<=360) && (ao>=315)) {return l}else{if (ao>=135) && (ao<=225)) {return k}else{ if ((ao>45) && (ao<135)) {return R}else{return c}}}}}function x () {var am=new Date (); return Am.gettime ()} function H () {a.unbind (AE,AA); A.unbind (I,D); A.unbind (K,G); A.unbind (Ac,o); V (False)}function W () {return r.pinchstatus| | r.pinchin| | R.pinchout}function AD () {return ak&&w ()}function L () {return a.data (t+ "_intouch") ===true?true:false} function V (AM) {am=am===true?true:false; A.data (t+ "_intouch", AM)}function al () {var am=[];for (var an=0;an<=5;an++) {Am.push ({start:{x:0,y:0},end:{x:0,y:0 },delta:{x:0,y:0}})}return am}}) (JQuery);

 

Related Article

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.