통합검색
로그인
회원가입
Open menu
로그인
회원가입
통합검색
Javascript
30
HTML/CSS
3
PHP
4
Travel
2
Javascript
30
HTML/CSS
3
PHP
4
Travel
2
Javascript
[Jquery] 특정 영역만 인쇄하기 - printThis
1
HTML <a href="#" id="btn_print">프린트하기</a> jquery // print $(document).ready(function() { $("#btn_print").click(function() { $("#prdt-view").printThis(); }); }); /* * printThis v2.0.0 * @desc Printing plug-in for jQuery * @author Jason Day * @author Samuel Rouse * * Resources (based on): * - jPrintArea: http://plugins.jquery.com/project/jPrintArea * - jqPrint: https://github.com/permanenttourist/jquery.jqprint * - Ben Nadal: http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm * * Licensed under the MIT licence: * http://www.opensource.org/licenses/mit-license.php * * (c) Jason Day 2015-2022 * * Usage: * * $("#mySelector").printThis({ * debug: false, // show the iframe for debugging * importCSS: true, // import parent page css * importStyle: true, // import style tags * printContainer: true, // grab outer container as well as the contents of the selector * loadCSS: "path/to/my.css", // path to additional css file - use an array [] for multiple * pageTitle: "", // add title to print page * removeInline: false, // remove all inline styles from print elements * removeInlineSelector: "body *", // custom selectors to filter inline styles. removeInline must be true * printDelay: 1000, // variable print delay * header: null, // prefix to html * footer: null, // postfix to html * base: false, // preserve the BASE tag, or accept a string for the URL * formValues: true, // preserve input/form values * canvas: true, // copy canvas elements * doctypeString: '...', // enter a different doctype for older markup * removeScripts: false, // remove script tags from print content * copyTagClasses: true // copy classes from the html & body tag * copyTagStyles: true, // copy styles from html & body tag (for CSS Variables) * beforePrintEvent: null, // callback function for printEvent in iframe * beforePrint: null, // function called before iframe is filled * afterPrint: null // function called before iframe is removed * }); * * Notes: * - the loadCSS will load additional CSS (with or without @media print) into the iframe, adjusting layout */ ; (function($) { function appendContent($el, content) { if (!content) return; // Simple test for a jQuery element $el.append(content.jquery ? content.clone() : content); } function appendBody($body, $element, opt) { // Clone for safety and convenience // Calls clone(withDataAndEvents = true) to copy form values. var $content = $element.clone(opt.formValues); if (opt.formValues) { // Copy original select and textarea values to their cloned counterpart // Makes up for inability to clone select and textarea values with clone(true) copyValues($element, $content, 'select, textarea'); } if (opt.removeScripts) { $content.find('script').remove(); } if (opt.printContainer) { // grab $.selector as container $content.appendTo($body); } else { // otherwise just print interior elements of container $content.each(function() { $(this).children().appendTo($body) }); } } // Copies values from origin to clone for passed in elementSelector function copyValues(origin, clone, elementSelector) { var $originalElements = origin.find(elementSelector); clone.find(elementSelector).each(function(index, item) { $(item).val($originalElements.eq(index).val()); }); } var opt; $.fn.printThis = function(options) { opt = $.extend({}, $.fn.printThis.defaults, options); var $element = this instanceof jQuery ? this : $(this); var strFrameName = "printThis-" + (new Date()).getTime(); if (window.location.hostname !== document.domain && navigator.userAgent.match(/msie/i)) { // Ugly IE hacks due to IE not inheriting document.domain from parent // checks if document.domain is set by comparing the host name against document.domain var iframeSrc = "javascript:document.write(\"<head><script>document.domain=\\\"" + document.domain + "\\\";</s" + "cript></head><body></body>\")"; var printI = document.createElement('iframe'); printI.name = "printIframe"; printI.id = strFrameName; printI.className = "MSIE"; document.body.appendChild(printI); printI.src = iframeSrc; } else { // other browsers inherit document.domain, and IE works if document.domain is not explicitly set var $frame = $("<iframe id='" + strFrameName + "' name='printIframe' />"); $frame.appendTo("body"); } var $iframe = $("#" + strFrameName); // show frame if in debug mode if (!opt.debug) $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); // before print callback if (typeof opt.beforePrint === "function") { opt.beforePrint(); } // $iframe.ready() and $iframe.load were inconsistent between browsers setTimeout(function() { // Add doctype to fix the style difference between printing and render function setDocType($iframe, doctype){ var win, doc; win = $iframe.get(0); win = win.contentWindow || win.contentDocument || win; doc = win.document || win.contentDocument || win; doc.open(); doc.write(doctype); doc.close(); &nbs···
[Jquery] 첨부파일 추가 삭제
HTML <div class="_fileWrap w100"> <div class="fileaddel"> <input type="file" placeholder="파일을 첨부해주세요."> <span class="btns"> <a href="#" data-fileadd="._fileWrap"><i class="axi axi-plus-circle"></i> 파일 추가</a><hr /> <a href="#" data-filedel="._fileWrap">파일 삭제</a> </span> </div> </div> CSS .fileaddel {width: calc(265px + 145px + 20px);position: relative;display: flex;justify-content: space-between;align-items: center;} .fileaddel .btns {display: flex;align-items: center;} .fileaddel .btns a {color: #444444;letter-spacing: -1px;} .fileaddel .btns a i {display: inline-block;vertical-align: -2px;font-size: 18px;color: #999999;} .fileaddel .btns hr {border: 0;padding: 0;margin: 0 13px;width: 1px;height: 10px;background: #bbb;} jquery //file add & del fileaddel = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'add' : '*[data-fileadd]', 'del' : '*[data-filedel]' } $(document).on('click', $ele.add, function(e){ e.preventDefault(); var $wrap = $(this).data('fileadd'); var $ele = $($wrap).last().clone(); // console.log($ele); $($wrap).last().after($ele); }) $(document).on('click', $ele.del, function(e){ e.preventDefault(); var $wrap = $(this).data('filedel'); $(this).closest($wrap).remove(); }) } } $(function(){ if($('*[data-fileadd]').length>0){ fileaddel.init(); } })
[Jquery] 화면 아래로 내려갔을때 class 추가
HTML <div id="fast-inquiry-form"> <div class="wrap"> <form action="#"> <fieldset class="inr"> <legend>창업문의</legend> <div class="tit"> <img src="<?=DIR?>/images/main/fast-inquiry-logo.png" alt=""> <p>가맹문의</p> <a href="tel:<?=$config_tel[0]?>"><?=$config_tel[0]?></a> </div> <div class="boxs"> <input type="text" class="inp" placeholder="성함"> <input type="text" class="inp" placeholder="연락처(’-’ 제외)"> <select class="sel"> <option value="">창업희망지역 선택</option> </select> </div> <div class="agree"> <input type="checkbox" id="_agree" name="_agree"> <label for="_agree">개인정보수집 동의</label> <a href="#" data-pop-href="<?=SUBPAGE?>/popup/private" data-pop-chain="pop1" data-pop-size="500,650">[확인]</a> </div> <input type="submit" value="문의하기" class="sbm"> </fieldset> </form> </div> </div> CSS #fast-inquiry-form {height: 100px;position: relative;z-index: 77;} #fast-inquiry-form legend {display: none;} #fast-inquiry-form .wrap {position: absolute;bottom: 0;left: 0;right: 0;height: 100px;background: var(--color);} #fast-inquiry-form .wrap .inr {height: 100px;display: flex;align-items: center;justify-content: space-between;max-width: 1400px;margin: 0 auto;} #fast-inquiry-form .tit {position: relative;padding-left: 75px;} #fast-inquiry-form .tit > img {position: absolute;bottom: 0;left: 0;} #fast-inquiry-form .tit > * {display: block;} #fast-inquiry-form .tit > p {font-size: 20px;color: #111111;font-weight: 800;line-height: 23px;} #fast-inquiry-form .tit > a {font-size: 32px;color: #111111;font-weight: 700;font-family: 'WAGURI';line-height: 35px;} #fast-inquiry-form .boxs {display: flex;align-items: center;} #fast-inquiry-form .boxs .inp, #fast-inquiry-form .boxs .sel {background: #fff;border: 0px;margin-right: 5px;padding: 0 20px;width: 220px;height: 55px;font-size: 18px;color: #777;box-sizing: border-box;} #fast-inquiry-form .boxs .sel option {color: #777;} #fast-inquiry-form .boxs .inp {padding-left: 20px;color: #111;} #fast-inquiry-form .boxs .inp::-webkit-input-placeholder{color: #777;} #fast-inquiry-form .boxs .inp:-moz-placeholder{color: #777;} #fast-inquiry-form .boxs .inp::-moz-placeholder{color: #777;} #fast-inquiry-form .boxs .inp:-ms-input-placeholder{color: #777;} #fast-inquiry-form .agree {display: flex;align-items: center;position: relative;z-index: 0;} #fast-inquiry-form .agree input {position: absolute;top: 0;left: 0;width: 0;height: 0;opacity: 0;overflow: hidden;} #fast-inquiry-form .agree a {font-weight: normal;font-size: 18px;color: #111;letter-spacing: -1px;line-height: 22px;font-weight: 500;text-decoration: none !important;} #fast-inquiry-form .agree label {font-weight: normal;font-size: 18px;color: #111;letter-spacing: -1px;line-height: 22px;font-weight: 700;margin-right: 5px;} #fast-inquiry-form .agree input + label {padding-left: 30px;position: relative;z-index: 0;} #fast-inquiry-form .agree input + label:after {display: block;content: '';position: absolute;top: -1px;left: 0;width: 24px;height: 24px;border-radius: 50%;border: 2px solid #111;box-sizing: border-box;} #fast-inquiry-form .agree input:checked + label:after {content: '\e116';font-family: 'axicon';font-size: 14px;color: #fff;background-color: #111;line-height: 20px;text-align: center;} #fast-inquiry-form .sbm {border: 0px;background: var(--color-red);width: 160px;height: 55px;font-weight: normal;font-size: 21px;color: #fff;font-weight: 700;} #fast-inquiry-form.fix .wrap {position: fixed;z-index: 55;} jquery //Bottom Fixed botFix = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'foot' : $('#footer'), 'wrap' : $('#fast-inquiry-form') } var classFix = function(){ var wt = $(window).scrollTop(); var wh = $(window).height(); var tt = $ele.foot.offset().top; if(wt < tt - wh){ $ele.wrap.addClass('fix'); }else{ $ele.wrap.removeClass('fix'); } } $(window).on({ 'load scroll' : function(){ classFix(); } }); } } $(function(){ if($('#fast-inquiry-form').length>0){ botFix.init(); } }) 참고사이트 : 노랑강정
[Jquery] 숫자 효과
1
jQuery <script type="text/javascript"> $(function(){ var loop = 0 $(window).on({ 'scroll load' : function(){ var st = parseInt($(window).scrollTop()); var pos = $('._counter').offset().top - ($(window).height() / 2); if(st >= pos && loop==0){ $("._counter strong").each(function(i){ $(this).flipping_text({ tickerTime: 30, tickerCount: 15, customRandomChar: "1234567890" }); }) loop++; } } }) }) </script> /* jQuery Plugin : counter number */ !function(e){function r(e,t){var n,r,i=t;this.pause=function(){window.clearTimeout(n);i-=new Date-r};this.resume=function(){r=new Date;n=window.setTimeout(e,i)};this.resume()}var t={tickerTime:10,customRandomChar:false,tickerCount:10,opacityEffect:true,resetOnChange:false};var n=false;e.fn.flipping_text=function(i){var s=this;resetAll=function(t){t.each(function(t){e(this).css({opacity:1,visibility:"visible"}).text(e(this).data("ft-text"))})};return this.each(function(o){function c(){var e=f.text(),t=0;if(a.customRandomChar!=false){var i=a.customRandomChar}else{var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"}f.attr("data-ft-text",e).html("");for(var s=0;s<l;s++){f.append("<span data-ft-bk='"+e.charAt(s)+"' class='ft_char"+s+"'></span>");var o=new r(function(){t=t+1;var e=0;if(n==true){return false}else{for(var s=0;s<a.tickerCount;s++){var o=f.find(".ft_char"+(t-1));var u=new r(function(){if(n==true){return false}else{if(e==a.tickerCount-2){o.css("opacity","1").text(o.data("ft-bk"));return false}else{if(a.opacityEffect==true){var t=e/a.tickerCount}else{var t=1}o.css("opacity",t).text(i.charAt(Math.floor(Math.random()*i.length)));e++}}},s*a.tickerTime)}}},(s+1)*a.tickerTime*a.tickerCount)}}if(e(this).data("delay")!==undefined){var u=e(this).data("delay")+0}else{var u=0}var a=e.extend({},t,i),f=e(this),l=f.text().length;if(a.resetOnChange==true){e(window).on("blur",function(){n=true;resetAll(s)})}f.css("visibility","hidden");var h=new r(function(){if(n==true){return false}else{f.css("visibility","visible");c()}},u*o)})}}(window.jQuery)
[Jquery] fullpage
2
fullpage 사용 방법 적용된 사이트 URL : 에이치케이세미텍 *2.9.7버전까지 무료 사용가능 HTML <div id="fullpage"> <article class="section visual"> <!-- visual ( type1: 위치 / type2: 이미지,동영상구분 ) --> <div class="roll"> <?php $main_banner_sql = banner_print('main_KOR', 'I', 500); while($main_banner_row = sql_fetch_array($main_banner_sql)){ ?> <div class="item"> <a href="<?=$main_banner_row['wm_link']?>" target="<?=$main_banner_row['wm_link_target']?>" style="background-image: url(<?=SP_DATA_URL?>/banner/<?=$main_banner_row['wm_upfile_name']?>);"> <img src="<?=SP_DATA_URL?>/banner/<?=$main_banner_row['wm_upfile_mo_name']?>" /> </a> </div> <?php } ?> </div> <div class="vis-control"> <button type="button" class="stop"><img src="/images/main/vis-stop.png" alt="stop"></button> <button type="button" class="play" style="display: none;"><img src="/images/main/vis-play.png" alt="play"></button> <button type="button" class="prev"><img src="/images/main/vis-prev.png" alt="prev"></button> <p class="vis-dots"> <span class="now">01</span>/<span class="tot">03</span> </p> <button type="button" class="next"><img src="/images/main/vis-next.png" alt="next"></button> </div> </article> <article class="section partners"> <div class="mtit"> <h3>partners</h3> </div> </article> <article class="section newsandnotice"> <div class="mtit"> <h3>newsandnotice</h3> </div> </article> <article class="section contactus"> <div class="mtit"> <h3>contactus</h3> </div> </article> <article class="section foot fp-auto-height"> <!-- s:footer --> <?php include PATH."/inc/foot.php"; ?> <!-- e:footer --> </article> </div> <!-- s:aside --> <aside id="aside"> <a href="#visual" data-menuanchor="visual">Main</a> <a href="#partners" data-menuanchor="partners">Partners</a> <a href="#newsandnotice" data-menuanchor="newsandnotice">News & Notice</a> <a href="#contactus" data-menuanchor="contactus">Contact us</a> <!-- <a href="#foot">foot</a> --> </aside> <!-- e:aside --> CSS #header {position: fixed;top: 0;left: 0;right: 0;height: 100px;background: rgba(0,0,0,0);background: #fff;} #aside {position: fixed;top: 50%;right: 80px;transform: translateY(-50%);display: flex;flex-direction: column;align-items: end;} #aside > a {margin: 9px 0;display: flex;align-items: center;position: relative;font-family: 'empty';font-size: 0;color: var(--color);font-weight: 700;} #aside > a:before {display: block;content: '';width: 7px;height: 7px;border-radius: 50%;background: #aaa;position: absolute;top: 12px;right: 12px;} #aside > a:after {opacity: 0;display: block;content: '';width: 32px;height: 32px;box-sizing: border-box;border-radius: 50%;border: 2px solid var(--color);margin-left: 12px;} #aside > a.active {font-family: 'Montserrat';font-size: 16px;} #aside > a.active:after {opacity: 1;} #aside > a.active:before {width: 10px;height: 10px;top: 11px;right: 11px;background: var(--color);} #fullpage .section {background: #444;} #fullpage .section:nth-child(odd) {background: #f1f1f1;} #fullpage .section:not(.foot, .visual) {padding-top: 100px;} #fullpage .section:not(.foot, .visual) .fp-tableCell {display: flex;justify-content: center;align-items: center;} #fullpage .section:not(.foot, .visual) .mtit > h3 {font-size: 42px;color: #fff;} #fullpage .section:nth-child(odd):not(.foot, .visual) .mtit > h3 {color: #222;} #main .visual{position: relative;} #main .visual .roll .item{position: relative;overflow: hidden;} #main .visual .roll .item a {display: block;height: 100vh;background-repeat: no-repeat;background-position: 50%;background-size: cover;} #main .visual .roll .item img{display: none;width: 100%;opacity: 0;} #main .visual .vis-control {position: absolute;bottom: 50px;left: calc(50% - 650px);display: flex;align-items: center;} #main .visual .vis-control * {color: #fff;} #main .visual .vis-control button {border: 0px;background: none;} jQuery // visual visual = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'roll' : $('.visual .roll') } var rolling = function(){ //item total number var tot_len = $('.visual .item').length; if (tot_len < 10) { tot_len = '0' + tot_len; } //10 이하 번호앞에 텍스트 0 입력 $('.visual .vis-dots .tot').text(tot_len); //slider $ele.roll.slick({ 'fade' : true, //Fade 롤링 효과 'dots' : false, //하단 pager 'arrows' : false, //next,prev 버튼 'infinite' : true, //무한반복 'slidesToShow' : 1, //슬라이드 갯수 'slidesToScroll' : 1, //롤링시 슬라이드 갯수 'autoplay' : true, //자동롤링 'autoplaySpeed' : 4000, //자동롤링 딜레이 'swipe' : false, //모바일 스와프 여부 'centerMode' : false, //Center모드. 가운데 slide에 'slick-active' 클래스 부여. 'centerPadding' : 0, //Center모드인 경우 좌/우 여백 설정 'vertical' : false, //vertical 모드 'zIndex' : 80, //z-index 'responsive' : [ //tablet { 'breakpoint' : 1300, 'settings' : { 'swipe' : true } } ] }); //현재 슬라이드 number $ele.roll.on('afterChange', function(event, slick, currentSlide, nextSlide){ now_len = currentSlide + 1; if (now_len < 1···
[Jquery] 이미지맵 반응형
2
jquery $(document).ready(function(){ //이미지맵이 있는 경우 반응형 이미지맵 처리 var coords = new Array(); function imagemap_coords(type){ $('area[coords2]').each(function(idx){ if(type=='ready'){ coords[idx] = $(this).attr('coords'); } var map_id = $(this).parent('map').attr('name'); var $img = $('img[usemap="#'+map_id+'"]'); var org_width = parseInt($img[0].naturalWidth); var now_width = $img.width(); var coords2 = coords[idx].split(','); var coords_re = ''; for(var i=0;i<coords2.length;i++){ coords_re += ','+coords2[i]*(now_width/org_width); } coords_re = coords_re.substring(1); $(this).attr('coords',coords_re); }); } imagemap_coords('ready'); $(window).resize(imagemap_coords); }); * 맵 api를 사용하는 경우 usemap 문제 발생할 수 있음. * 그런 경우 area 에 attribute 추가해서 사용할 것
[Jquery] 입력한 글자 수 체크
jquery // 입력한 글자수 체크 $('#content1').keyup(function (e){ var content = $(this).val(); $('#bytes1').html(content.length);//글자수 실시간 카운팅 if (content.length > 500){ alert("최대 1000자까지 입력 가능합니다."); $(this).val(content.substring(0, 500)); $('#bytes1').html("500"); } }); $('#content1').trigger('keyup');
[Jquery] 즐겨찾기 버튼
HTML <a calss="btn1" id="favorite">즐겨찾기</a> jquery //즐겨찾기 $(document).ready(function() { $(document).on('click', '#favorite', function(e) { var bookmarkURL = window.location.href; var bookmarkTitle = document.title; var triggerDefault = false; if (window.sidebar && window.sidebar.addPanel) { // Firefox version < 23 window.sidebar.addPanel(bookmarkTitle, bookmarkURL, ''); } else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)) || (window.opera && window.print)) { // Firefox version >= 23 and Opera Hotlist var $this = $(this); $this.attr('href', bookmarkURL); $this.attr('title', bookmarkTitle); $this.attr('rel', 'sidebar'); $this.off(e); triggerDefault = true; } else if (window.external && ('AddFavorite' in window.external)) { // IE Favorite window.external.AddFavorite(bookmarkURL, bookmarkTitle); } else { // WebKit - Safari/Chrome alert((navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D 키를 눌러 즐겨찾기에 등록하실 수 있습니다.'); } return triggerDefault; }); });
[Jquery] 스크롤 시 해당 영역에 class 추가
CSS @media screen and (min-width: 1300px){ /* action */ #main-group .tt > * {opacity: 0;top: -50px;} #main-group.active .tt > * {opacity: 1;top: 0;} #main-group.active .tt > h3 {transition: all 0.5s 0s;} #main-group.active .tt > p {transition: all 0.5s 0.5s;} #main-group.active .tt > span {transition: all 0.5s 1s;} #main-group.active .tt > a {transition: all 0.5s 1.5s;} } jquery //scroll section active section_active = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'ani' : $('._ani'), 'win' : $(window), } $ele.win.on('load scroll', function(){ $ele.ani.each(function(i){ if( ( $ele.win.scrollTop() + ($ele.win.height() / 2) ) > $ele.ani.eq(i).offset().top ){ $(this).addClass('active'); }else{ $(this).removeClass('active'); } }); }); } } $(function(){ if($('#main ._ani').length>0){ section_active.init(); } }) 참고 사이트 : 저스트그룹
[Jquery] header 상단에서만 특정 class 추가
jquery //header bg headBg = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'win' : $(window), 'hd' : $('#header') } $ele.win.on({ 'scroll resize load' : function(){ var wt = $ele.win.scrollTop(); var hh = $ele.hd.height(); //console.log(wt); if(wt > hh){ $ele.hd.addClass('fix'); } else { $ele.hd.removeClass('fix'); } } }); } } $(function(){ if($('#header').length>0){ headBg.init(); } })
[Jquery] 메뉴 버튼 클릭 시 특정 위치로 스크롤 이동
HTML <ul id="gnb"> <li class="first"><a href="#">main</a></li> <li><a href="#">menu1</a></li> <li><a href="#">menu2</a></li> </ul> </ul> <div id="landing"> <article class="section visual"> <div class="mtit"> <h3>visual</h3> </div> </article> <article class="section menu1"> <div class="mtit"> <h3>‘menu1</h3> </div> </article> <article class="menu2"> <div class="mtit"> <h3>menu2</h3> </div> </article> </div> CSS #landing .section {min-height: 100vh;display: flex;justify-content: center;align-items: center;} #landing .section:nth-child(even) {background: #333;} #landing .section:nth-child(even) .mtit > h3 {color: #fff;} .mtit {display: flex;justify-content: center;align-items: center;flex-direction: column;} .mtit > * {display: block;text-align: center;} .mtit > h3 {font-size: 32px;line-height: 42px;color: #333;font-weight: 700;} Jquery //section target section_target = { 'init' : function(){ this.action(); }, 'action' : function(){ //aside Active 처리 var $ele = { 'win' : $(window), 'sec' : $('#landing .section'), 'btnWrap' : $('#gnb'), 'btnOn' : $('#gnb > li'), 'btn' : '#gnb > li > a', } var wh = []; var secNum = 0; $ele.sec.each(function(i){ wh[i] = $ele.sec.eq(i).offset().top; }); $(document).on('click', $ele.btn, function(e){ var i = $(this).parent('li').index(); var pos = $('.section').eq(i).offset().top; e.preventDefault(); $('html,body').animate({ 'scrollTop' : pos },600,'easeInOutQuart'); return false; }); function acc(){ $ele.btnOn.eq(secNum).addClass('active').siblings().removeClass('active'); if(secNum==0){ $ele.btnWrap.addClass('home-on'); }else{ $ele.btnWrap.removeClass('home-on'); } } acc(); $ele.win.on({ 'load scroll resize' : function(){ var sh = parseInt($(this).scrollTop()); for (i=0; i < $ele.sec.length; i++){ if(sh >= parseInt(wh[i]) - ($ele.win.height()/2)){ secNum = i; acc(); } } } }); } } $(function(){ $(window).on({ 'load' : function(){ if($('#landing .section').length>0){ section_target.init(); } } }); }) 참고 사이트 : 노랑강정
[Jquery] 수량 증가 감소 버튼
HTML <div class="count-wrap _count"> <button type="button" class="minus">감소</button> <input type="text" class="inp" value="1" /> <button type="button" class="plus">증가</button> </div> CSS .count-wrap {position: relative;border: 1px solid #ddd;overflow: hidden;width: calc(52px + 34px*2);display: flex;align-items: center;box-sizing: border-box;} .count-wrap > button {border: 0;background: #fff;color: #000;width: 34px;height: 34px;font-size: 12px;} .count-wrap .inp {border: 1px solid #ddd;border-width: 0 1px !important;height: 34px !important;margin: 0 !important;display: block;width: 100%;padding: 0;flex-grow: 1;flex-basis: 0;text-align: center;} jQuery //수량 옵션count_number = { 'init' : function() { this.action(); }, 'action' : function() { var $ele = { 'btn' : $('._count :button') } $ele.btn.on({ 'click' : function(e){ e.preventDefault(); var $count = $(this).parent('._count').find('.inp'); var now = parseInt($count.val()); var min = 1; var max = 999; var num = now; if($(this).hasClass('minus')){ var type = 'm'; }else{ var type = 'p'; } if(type=='m'){ if(now>min){ num = now - 1; } }else{ if(now<max){ num = now + 1; } } if(num != now){ $count.val(num); } } }); } } $(function() { if($('._count :button').length>0){ count_number.init(); } });
[Jquery] 우클릭 및 드래그 막기
jQuery //우클릭 금지 $(document).bind('contextmenu',function(e){ return false; }); //드래그 금지 $('*').bind('selectstart',function(e){ return false; });
[Jquery] tab
HTML <div class="_tabWrap"> <div class="tab-tab"> <a href="#">제목1</a> <a href="#">제목2</a> </div> <div class="tab-article"> <article>내용1</article> <article>내용2</article> </div> </div> jQuery $(function(){ $('._tabWrap').tab(); }) $(function(){ $('._tabWrap').tab({ 'tabAfter' : function() { //실행 }, 'loadAfter' : function() { //실행 } }); }) /* jQuery Plugin : tab */ $(function(){$.fn.tab=function(options,callback){return this.each(function(){var $el=$(this);$.fn.tab.defaults={tab:$('.tab-tab'),article:$('.tab-article'),className:'active',mode:'normal',tabAfter:'',loadAfter:''};var option=$.extend({},$.fn.tab.defaults,options);var $tab=$('> *',$el.find(option.tab));var $article=$('> *',$el.find(option.article));function init(){tab_mark_no();article_mark_no();start();loadAfter()}function tab_mark_no(){$tab.each(function(i){$(this).attr('tab',i);if(i==0){$(this).addClass(option.className)}})}function article_mark_no(){$article.each(function(i){$(this).attr('tab',i);if(i>0){$(this).hide()}})}function tabAfter(){if(option.tabAfter){eval(option.tabAfter())}}function loadAfter(){if(option.loadAfter){eval(option.loadAfter())}}function start(){$tab.click(function(e){e.preventDefault();var no=$(this).attr('tab');$(this).addClass(option.className).siblings().removeClass(option.className);$article.each(function(){var hasTab=$(this).attr('tab');if(typeof hasTab!==typeof undefined&&hasTab!==false&&hasTab==no){switch(option.mode){case'fade':$(this).fadeIn();break;default:$(this).show();break}}else{$(this).hide()}});tabAfter()})}init()})}});
[Jquery] slick slider
slick 슬라이더 사용 방법 사이트 URL : https://kenwheeler.github.io/slick/ HTML <div class="visual"> <div class="roll"> <div class="item">slider1</div> <div class="item">slider2</div> <div class="item">slider3</div> </div> <p class="vis-dots"> <span class="now">01</span> / <span class="tot">03</span> </p> <div class="vis-control"> <button class="play">play</button> <button class="stop">stop</button> </div> </div> jQuery //visual visual = { 'init' : function(){ this.action(); }, 'action' : function(){ var $ele = { 'roll' : $('.visual .roll') } var rolling = function(){ //item total number var tot_len = $('.visual .item').length; if (tot_len < 10) { tot_len = '0' + tot_len; } //10 이하 번호앞에 텍스트 0 입력 $('.visual .vis-dots .tot').text(tot_len); //slider $ele.roll.slick({ 'fade' : false, //Fade 롤링 효과 'dots' : true, //하단 pager 'arrows' : true, //next,prev 버튼 'infinite' : true, //무한반복 'slidesToShow' : 1, //슬라이드 갯수 'slidesToScroll' : 1, //롤링시 슬라이드 갯수 'autoplay' : true, //자동롤링 'autoplaySpeed' : 4000, //자동롤링 딜레이 'swipe' : false, //모바일 스와프 여부 'centerMode' : false, //Center모드. 가운데 slide에 'slick-active' 클래스 부여. 'centerPadding' : 0, //Center모드인 경우 좌/우 여백 설정 'vertical' : false, //vertical 모드 'zIndex' : 80, //z-index 'responsive' : [ //tablet { 'breakpoint' : 1300, 'settings' : { 'swipe' : true } }, //mobile { 'breakpoint' : 750, 'settings' : { 'swipe' : true } } ] }); //현재 슬라이드 number $ele.roll.on('afterChange', function(event, slick, currentSlide, nextSlide){ now_len = currentSlide + 1; if (now_len < 10) { now_len = '0' + now_len; } //10 이하 번호앞에 텍스트 0 입력 $('.visual .vis-dots .now').text(now_len); }); //control play $('.vis-control .play').click(function(){ $ele.roll.slick('slickPlay'); }); //control stop $('.vis-control .stop').click(function(){ $ele.roll.slick('slickPause'); }); } rolling(); } } $(function(){ if($('.visual').length>0){ visual.init(); } }) 영상 같이 슬라이드 HTML <div class="visual"> <div class="roll"> <div class="item" data-src="<div class='video'><video class='vis_video pc' autoplay muted playsinline><source src='<?=DIR?>/files/main.mp4' type='video/mp4'></video><video class='vis_video mobile' autoplay muted playsinline><source src='<?=DIR?>/files/main.mp4' type='video/mp4'></video></div>"> <div class="video"> <!-- controls autoplay muted loop playsinline --> <video class="vis_video pc" autoplay muted playsinline> <source src="<?=DIR?>/files/main.mp4" type="video/mp4"> </video> <video class="vis_video mobile" autoplay muted playsinline> <source src="<?=DIR?>/files/main.mp4" type="video/mp4"> </video> </div> </div> <div class="item"> <a href="#" target="_blank" class="__pc"><img src="<?=DIR?>/images/main/visual1.jpg" /></a> <a href="#" target="_blank" class="__ta"><img src="<?=DIR?>/images/main/visual1.jpg" /></a> <a href="#" target="_blank" class="__mo"><img src="<?=DIR?>/images/main/visual1.jpg" /></a> </div> </div> </div> CSS #main .visual .video {position: relative;z-index: 0;width: 100vw;height: 900px;overflow: hidden;} #main .visual .video video {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);min-width: 100%;min-height: 100%;width: auto;height: auto;} #main .visual .video video.pc {display: block;} #main .visual .video video.mobile {display: none;} jQuery // visual visual = { 'init' : function() { this.action(); }, 'action' : function() { var $video_pc = $('.vis_video.pc'); var $video = $('.vis_video.mobile'); var $ele = { 'win' : $('window'), 'roll' : $('.visual .roll') } var rolling = function() { $ele.roll.slick({ 'fade' : true, // Fade 롤링 효과 'dots' : true, // 하단 pager 'arrows' : false, // n···
1
2