Dev Blog

스크립트 & 소스코드 공유

실무에서 유용하게 쓰는 스크립트와 코드 조각을 블로그 게시판으로 저장하고 공유합니다.

jQuery jQuery BlackAndWhite 플러그인으로 이미지 흑백 효과 적용하기

페이지 정보

조회 204회 작성일 20-04-28 17:22
jQuery.BlackAndWhite 플러그인을 이용해 이미지에 흑백 효과를 적용하는 방법을 4단계로 설명한다. jQuery와 플러그인 스크립트를 로드하고, 흑백 처리할 이미지의 래퍼에 bwWrapper 클래스를 지정한 뒤 CSS로 래퍼 스타일을 설정하고, window load 시점에 플러그인을 초기화한다. hoverEffect, intensity, responsive, speed 등 주요 옵션도 소개한다.

1 add jQuery and plug in to the page

<script src="js/jquery.min.js"></script>
<script src="js/jQuery.BlackAndWhite.js"></script>

2 add this class to the wrapper of the image that you want make in Black and White

<div class="bwWrapper">
<img src="path/to/your/image" width="image width" height="image height">
</div>

3 set the wrapper in this way from the css:

.bwWrapper {
position:relative;
display:block;
}

4 initialize the plug in on window load (no $(document).ready()) :

$(window).load(function(){
$('.bwWrapper').BlackAndWhite({
hoverEffect : true, // default true
// set the path to BnWWorker.js for a superfast implementation
webworkerPath : false,
// for the images with a fluid width and height
responsive:true,
// this option works only on the modern browsers ( on IE lower than 9 it remains always 1)
intensity:1,
speed: { //this property could also be just speed: value for both fadeIn and fadeOut
fadeIn: 200, // 200ms for fadeIn animations
fadeOut: 800 // 800ms for fadeOut animations
}
});
});


Let's create something great together.

프로젝트 문의 및 견적 요청은 언제든 환영합니다.