HTML代码:

Home >Web Front-end >JS Tutorial >Original image comparison curtain effect implemented by jQuery_jquery

Original image comparison curtain effect implemented by jQuery_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:44:361779browse

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

Copy code The code is as follows:











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 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' });
}
});
});
Statement:
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