forked from jotform/before-after.js
/
before-after.min.js
executable file
·1 lines (1 loc) · 1.2 KB
/
before-after.min.js
1
function drags(e,a,t){e.on("mousedown touchstart",function(s){e.addClass("draggable"),a.addClass("resizable");var i=s.pageX?s.pageX:s.originalEvent.touches[0].pageX,n=e.outerWidth(),o=e.offset().left+n-i,l=t.offset().left,u=t.outerWidth();minLeft=l+10,maxLeft=l+u-n-10,e.parents().on("mousemove touchmove",function(e){var t=e.pageX?e.pageX:e.originalEvent.touches[0].pageX;leftValue=t+o-n,leftValue<minLeft?leftValue=minLeft:leftValue>maxLeft&&(leftValue=maxLeft),widthValue=100*(leftValue+n/2-l)/u+"%",$(".draggable").css("left",widthValue).on("mouseup touchend touchcancel",function(){$(this).removeClass("draggable"),a.removeClass("resizable")}),$(".resizable").css("width",widthValue)}).on("mouseup touchend touchcancel",function(){e.removeClass("draggable"),a.removeClass("resizable")}),s.preventDefault()}).on("mouseup touchend touchcancel",function(){e.removeClass("draggable"),a.removeClass("resizable")})}$(document).ready(function(){$(".ba-slider").each(function(){var e=$(this),a=e.width()+"px";e.find(".resize img").css("width",a),drags(e.find(".handle"),e.find(".resize"),e)})}),$(window).resize(function(){$(".ba-slider").each(function(){var e=$(this),a=e.width()+"px";e.find(".resize img").css("width",a)})});