Mobile phone app finger sliding switch pictures special effects attached source code download _jquery

Source: Internet
Author: User
Tags abs

This is a very cool effect of mobile phone app sliding finger switch picture effects. The app special effects in mobile phone users can slide around the finger to switch pictures, in the desktop device through the mouse can also achieve the same effect.

Effect Demo Source Download

How to use

HTML structure

The mobile phone app's HTML structure for switching image effects is nested <div> html, with each picture card wrapped in div.demo__card, with pictures, descriptions, and additional layers.

<div class= "Demo__card" >
 <div class= "Demo__card__top Brown" >
 <div class= "Demo__card__img" ></div>
 <p class= "Demo__card__name" >hungry cat</p>
 </div>
 <div class= " Demo__card__btm ">
 <p class=" Demo__card__we ">Whatever</p>
 </div>
 <div class= "Demo__card__choice m--reject" ></div>
 <div class= "Demo__card__choice m--like" ></div>
 <div class= "Demo__card__drag" ></div>

M--reject is the layer that moves the picture to the left, M--like is the layer that moves the picture to the right, Demo__card__drag is the drag layer.

Javascript

In the jquery code, the Pullchange () function is used to set the rotation angle and transparency of the two sliding layers to the left and right. The release () function is used to determine whether the user slides the finger to the left or right and adds the corresponding class to the DOM element for these actions.

function Pullchange () {animating = true;
 deg = PULLDELTAX/10;
 $card. CSS (' transform ', ' Translatex (' + pulldeltax + ' px ') rotate (' + deg + ' deg) ');
 var opacity = pulldeltax/100; var rejectopacity = opacity >= 0?
 0:math.abs (opacity); var likeopacity = opacity <= 0?
 0:opacity;
 $cardReject. CSS (' opacity ', rejectopacity);
$cardLike. CSS (' opacity ', likeopacity);
}
;
 Function Release () {if (Pulldeltax >= decisionval) {$card. addclass (' to-right ');
 else if (pulldeltax <=-decisionval) {$card. addclass (' To-left ');
  } if (Math.Abs (pulldeltax) >= decisionval) {$card. addclass (' inactive ');
   settimeout (function () {$card. addclass (' below '). Removeclass (' inactive to-left to-right ');
   cardscounter++;
    if (Cardscounter = = numofcards) {cardscounter = 0;
   $ ('. Demo__card '). Removeclass (' below ');
 }, 300);
 } if (Math.Abs (Pulldeltax) < Decisionval) {$card. addclass (' reset '); } settimeout (function () {$card. attr (' style ', '). removeclAss (' reset '). Find ('. Demo__card__choice '). attr (' style ', ');
  Pulldeltax = 0;
 animating = false;
}, 300);  };

Finally, the MouseDown and touchstart events are monitored and a card switching operation is performed on the card elements that are not. Inactive.

How to use

HTML structure

The mobile phone app's HTML structure for switching image effects is nested <div> html, with each picture card wrapped in div.demo__card, with pictures, descriptions, and additional layers.

<div class= "Demo__card" >
 <div class= "Demo__card__top Brown" >
 <div class= "Demo__card__img" ></div>
 <p class= "Demo__card__name" >hungry cat</p>
 </div>
 <div class= " Demo__card__btm ">
 <p class=" Demo__card__we ">Whatever</p>
 </div>
 <div class=" Demo__card__choice m--reject "></div>
 <div class=" Demo__card__choice m--like "></div>
 <div class= "Demo__card__drag" ></div>

M--reject is the layer that moves the picture to the left, M--like is the layer that moves the picture to the right, Demo__card__drag is the drag layer.

Javascript

In jquery code, the Pullchange () function sets the rotation angle and transparency of the two sliding layers to the left and right. The release () function is used to determine whether the user slides the finger to the left or right and adds the corresponding class to the DOM element for these actions.

function Pullchange () {animating = true;
 deg = PULLDELTAX/10;
 $card. CSS (' transform ', ' Translatex (' + pulldeltax + ' px ') rotate (' + deg + ' deg) ');
 var opacity = pulldeltax/100; var rejectopacity = opacity >= 0?
 0:math.abs (opacity); var likeopacity = opacity <= 0?
 0:opacity;
 $cardReject. CSS (' opacity ', rejectopacity);
$cardLike. CSS (' opacity ', likeopacity);
}
;
 Function Release () {if (Pulldeltax >= decisionval) {$card. addclass (' to-right ');
 else if (pulldeltax <=-decisionval) {$card. addclass (' To-left ');
  } if (Math.Abs (pulldeltax) >= decisionval) {$card. addclass (' inactive ');
   settimeout (function () {$card. addclass (' below '). Removeclass (' inactive to-left to-right ');
   cardscounter++;
    if (Cardscounter = = numofcards) {cardscounter = 0;
   $ ('. Demo__card '). Removeclass (' below ');
 }, 300);
 } if (Math.Abs (Pulldeltax) < Decisionval) {$card. addclass (' reset '); } settimeout (function () {$card. attr (' style ', '). removeclAss (' reset '). Find ('. Demo__card__choice '). attr (' style ', ');
  Pulldeltax = 0;
 animating = false;
}, 300); };

Finally, the MouseDown and touchstart events are monitored and a card switching operation is performed on the card elements that are not. Inactive.

$ (document). On (' MouseDown touchstart ', '. Demo__card:not (. Inactive) ', function (e) {
 if (animating) return
  ;
 $card = $ (this);
 $cardReject = $ ('. Demo__card__choice.m--reject ', $card);
 $cardLike = $ ('. Demo__card__choice.m--like ', $card);
 var startx = E.pagex | | E.originalevent.touches[0].pagex;
 $ (document). On (' MouseMove touchmove ', function (e) {
  var x = E.pagex | | e.originalevent.touches[0].pagex;
  Pulldeltax = X-startx;
  if (!pulldeltax) return
   ;
  Pullchange ();
 });
 $ (document). On (' MouseUp touchend ', function () {
  $ (document). Off (' MouseMove touchmove mouseup touchend ');
  if (!pulldeltax) return
   ;
  Release ();
 });
    

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.