티스토리 뷰
메일폼 등에서 이미지 특정부분에 링크를 걸어야 하는 경우 이미지맵 사용
이미지맵은 이미지 상의 좌표값을 활용하기 때문에 기본적으로 반응형이 적용되지 않는다
그래서 이미지맵의 좌표값들이 반응형으로 적용되도록 플러그인 사용 (rwdImageMaps)
/*
* rwdImageMaps jQuery plugin v1.6
*
* Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
*
* Copyright (c) 2016 Matt Stow
* https://github.com/stowball/jQuery-rwdImageMaps
* http://mattstow.com
* Licensed under the MIT license
*/
;(function($) {
$.fn.rwdImageMaps = function() {
var $img = this;
var rwdImageMap = function() {
$img.each(function() {
if (typeof($(this).attr('usemap')) == 'undefined')
return;
var that = this,
$that = $(that);
// Since WebKit doesn't know the height until after the image has loaded, perform everything in an onload copy
$('<img />').on('load', function() {
var attrW = 'width',
attrH = 'height',
w = $that.attr(attrW),
h = $that.attr(attrH);
if (!w || !h) {
var temp = new Image();
temp.src = $that.attr('src');
if (!w)
w = temp.width;
if (!h)
h = temp.height;
}
var wPercent = $that.width()/100,
hPercent = $that.height()/100,
map = $that.attr('usemap').replace('#', ''),
c = 'coords';
$('map[name="' + map + '"]').find('area').each(function() {
var $this = $(this);
if (!$this.data(c))
$this.data(c, $this.attr(c));
var coords = $this.data(c).split(','),
coordsPercent = new Array(coords.length);
for (var i = 0; i < coordsPercent.length; ++i) {
if (i % 2 === 0)
coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent);
else
coordsPercent[i] = parseInt(((coords[i]/h)*100)*hPercent);
}
$this.attr(c, coordsPercent.toString());
});
}).attr('src', $that.attr('src'));
});
};
$(window).resize(rwdImageMap).trigger('resize');
return this;
};
})(jQuery);
$(document).ready(function(e) {
$('img[usemap]').rwdImageMaps();
});
출처
https://github.com/stowball/jQuery-rwdImageMaps
'WebPublisher > JavaScript & jQuery' 카테고리의 다른 글
[javaScript] daterangepicker (0) | 2022.11.11 |
---|---|
[jQuery] 더보기 버튼 load more (0) | 2022.11.11 |
[jQuery] split 활용해 한 페이지에서 url 다르게 tab 링크 설정 (0) | 2022.08.18 |
[jQuery] 배너 sticky 이벤트 (0) | 2022.08.17 |
[JavaScript] 페이지 자동 인쇄하기 (auto print) (0) | 2022.07.27 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- php조건문축약형
- 이미지onerror
- flipjavascript
- calendarflipanimation
- 스크롤커스텀css
- 경력직웹퍼블리셔이직
- php조건문
- 텍스트플로팅효과
- 흘러가는텍스트효과
- 스티키효과
- rwdImageMaps
- 2단레이아웃반응형
- marquee html
- 에러이미지마크업
- a태그다운로드
- 퍼블리셔이직
- calendarflipjavascript
- phpif조건문
- flipanimation
- flipjavascriptanimation
- sticky제이쿼리
- 그리드반응형
- marquee css
- 이미지맵반응형
- 자동인쇄script
- marquee javascript
- clockflipanimation
- 에러이미지속성
- 인쇄스크립트
- 스크롤커스텀
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함