본문 바로가기

웹프로그래밍/Javascript

(26)
Javascript iBook EPUB 3.0 Images not working iBook 에서 이미지를 클릭 했을때 동적으로 div를 생성하고 그 안에 background-image 스타일 지정을 해주었으나 도통 빈 칸만 뜨고 이미지가 출력되지 않았다. 콘솔로그를 찍어볼 수 없는 거지같은 테스트환경이어서 html 마크업으로 일일히 확인해본 결과 이미지를 불러올때 ibooksimg:// 라는 프로토콜을 사용해야 하지만 ibooks:// 로 불러오면서 이미지가 출력되지 않은 것이었다. var str = $("img").get(0).src; str = str.replace("ibooks://", "ibooksimg://"); 로 간단히 replace 치환처리 하니 정상 출력되었다.
jQuery $("img").load non-cache 이미지의 원본 크기를 구하기 위해서 $("img").get(0).naturalWidth 이나 naturalHeight 를 변수에 초기화했을때, 0 값이 떨어진다. 이러한 현상을 막기 위해서 $("img").load(function(){ var img = { width:$(this).get(0).naturalWidth, height:$(this).get(0).naturalHeight }); 등으로 사용할 수 있다. 그런데 여기서 load 된 값이 캐슁처리되면서 더이상 load가 실행되지 않는다. 이때 아래와 같은 방법으로 대응가능하다. $("img").one("load",function(){ var img = { width:$(this).get(0).naturalWidth, height:$(this).ge..
jQuery Animation Rotate $({deg: 0}).animate({deg: d},{ duration: cf.duration, step: function(now) { ev.css({ transform: 'rotate(' + now + 'deg)' }); } });
Javascript 모바일 체크 var mobilecheck = function() { var check = false; (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|63..
Javascript Favicon 적용 (function() { var link = document.createElement('link'); link.type = 'image/x-icon'; link.rel = 'shortcut icon'; link.href = '/resources/pubtree/images/favicon.ico'; document.getElementsByTagName('head')[0].appendChild(link); }());
input type=text 에서 엔터 눌렀을때 submit 실행 1. onkeydown="javascript: if (event.keyCode == 13) {chkform();}" 이런식으로 체크한다. 함수 호출로 chkform(); view source print? 01.function chkform() 02.{ 03.var f = document.fo_search; 04.if(f.addr1.value == '') 05.{ 06. alert('지역을 선택해주세요.'); 07. f.addr1.focus(); 08. return false; 09.}else{ 10. document.fo_search.submit(); 11.} 12.} document.fo_search.submit(); 이런식으로 form의 submit 실행
Javascript 오른쪽 마우스 버튼 막기 function detectLeftButton(evt){ evt = evt || window.event;var button = evt.which || evt.button;return button == 1; }
Javascript 페이지에서 가장 큰 z-index 구하기 function maxZ(){ return Math.max.apply(null,$.map($('body > *'), function(e,n){if($(e).css('position')=='absolute')return parseInt($(e).css('z-index'))||1;})); }