返回 jQuery 实例与特效代码列表
图片与媒体MIT兼容 jQuery 1.12 / 3.8 / 4.1
图片前后对比滑块
拖动滑块左右对比修图、滤镜或去水印前后的图像效果,兼容鼠标与触屏操作。
兼容性说明:全版本兼容(含 slim 精简版)。
在线交互演示(独立沙箱)
$(function () {
function update(pct) {
$('#ic-before').css('clip-path', 'inset(0 ' + (100 - pct) + '% 0 0)');
$('#ic-line').css('left', pct + '%');
}
$('#ic-range').on('input change', function () {
update(Number($(this).val()));
});
update(50);
});不用 jQuery 怎么写?(现代原生 JS / CSS 替代思路)
用原生 <input type="range"> 覆盖在双图上方,拖动时更新 CSS 变量 --pos 驱动 clip-path。
range.addEventListener('input', () => stage.style.setProperty('--pos', range.value + '%'));