-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.convertToBackground.min.js
9 lines (9 loc) · 1.15 KB
/
jquery.convertToBackground.min.js
1
2
3
4
5
6
7
8
9
/**
* Convert To Background
*
* Version: 1.1.1
* Author: Zeshan Ahmed
* Website: https://zeshanahmed.com/
* Github: https://github.com/zeshanshani/jquery-convert-to-background/
*/
!function(p){p.fn.convertToBackground=function(t){var g=p.extend({repeat:"no-repeat",position:"center center",size:"cover",attachment:"",fallbackSrc:"",width:"",height:"",responsive:!1},t);p(this).each(function(t,e){var i=p(this),a=i.find("img").eq(0),n=a.attr("src"),o=!0===g.responsive,c=g.width,r=c?"100%":"",d=g.height,h=p("<div></div>"),s="";o&&c&d&&(i.append(h),d=0,s=100*g.height/g.width+"%"),o&&i.find(h)?h.css({backgroundRepeat:g.repeat,backgroundPosition:g.position,backgroundSize:g.size,backgroundAttachment:g.attachment,backgroundImage:"url("+(n||g.fallbackSrc)+")",height:d,width:"100%",paddingBottom:s}):i.css({backgroundRepeat:g.repeat,backgroundPosition:g.position,backgroundSize:g.size,backgroundAttachment:g.attachment,backgroundImage:"url("+(n||g.fallbackSrc)+")",height:d,paddingBottom:s}),i.css({width:c,maxWidth:r}),a.css({position:"absolute",width:"1px",height:"1px",padding:"0",overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:"0"})})}}(jQuery);