HTML代码:
Home > Web Front-end > JS Tutorial > body text

Original image comparison curtain effect implemented by jQuery_jquery

WBOY
Release: 2016-05-16 16:44:36
Original
1709 people have browsed it

Effect:
Original image comparison curtain effect implemented by jQuery_jquery
HTML code:

Copy code The code is as follows:






< img alt="" src="js/VFX-after.jpg">




JS code:
Copy code The code is as follows:

$(function () {
//Outer DIV
var imageWrap = $('.vfx-image-wrap' ),
//Foreground image
topImage = $(this).find('.before-image'),
//Dividing line
divider = $(this).find('. divider-bar'),
stayBounce = $('.toggle-function');

imageWrap.on("mousemove", function (e) {
// Gotta localize top image and divider so it only applies to this
var offsets = $(this).offset(),
fullWidth = $(this).width(),
mouseX = e.pageX - offsets.left,
topImage = $(this).find('.before-image'),
divider = $(this).find('.divider-bar');

if (mouseX < 0) {
mouseX = 0;
} else if (mouseX > fullWidth) {
mouseX = fullWidth
}
$(this).addClass('special');
divider.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')) {
divider.css({ left: '50%', transition: 'all .3s' });
topImage.css({ width: '50%', transition: 'all .3s' });
}
});
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template