Comparison of curtain effects with original images implemented by jQuery _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces jQuery's original image comparison and curtain effect. If you need it, refer to the following results:

HTML code:

The Code is as follows:












JS Code:

The Code is as follows:


$ (Function (){
// External DIV
Var imageWrap = $ ('. vfx-image-wrapp '),
// Foreground chart
TopImage = $ (this). find ('. before-image '),
// Split line
Pider = $ (this). find ('. pider-bar '),
StayBounce = $ ('. toggle-function ');

ImageWrap. on ("mousemove", function (e ){
// Gotta localize top image and pider so it only applies to this
Var offsets = $ (this). offset (),
FullWidth = $ (this). width (),
MouseX = e. pageX-offsets. left,
TopImage = $ (this). find ('. before-image '),
Pider = $ (this). find ('. pider-bar ');

If (mouseX <0 ){
MouseX = 0;
} Else if (mouseX> fullWidth ){
MouseX = fullWidth
}
$ (This). addClass ('special ');
Pider.css ({left: mouseX, transition: 'none '});
TopImage.css ({width: mouseX, transition: 'none '});
});
StayBounce. click (function (){
$ (This). toggleClass ('stay ');
});

ImageWrap. on ("mouseleave", function (){
If (! StayBounce. hasClass ('stay ')){
Pider.css ({left: '000000', transition: 'All. 3s '});
TopImage.css ({width: '000000', transition: 'All. 3s '});
}
});
});

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.