본문 바로가기

Js47

replace(), 유튜브 클릭시 오토플레이 유튜브 주소 뒤에 ?autoplay=1 붙이기 var currentUrl = $('iframe').attr('src');$('.video').click(function(e){ e.preventDefault(); $('#overlay').addClass('visible'); var newStr = '?autoplay=1'; var newUrl = currentUrl.concat(newStr); $('iframe').attr('src', newUrl);});$('.close').click(function(e){ e.preventDefault(); currentUrl = $('iframe').attr('src'); $('#overlay').removeClass('vi.. 2024. 7. 17.
숫자 카운터 var box = $('.box'), boxin = box.find('.boxin'), rate = box.find('.rate'), rateNum = rate.attr('data-rate'); boxin.animate({width:rateNum + '%'}, 2000);//첫번째 // setInterval(textAni, 100);// function textAni(){// var currentRate = boxin.width() / box.width() * 100;// rate.text( Math.ceil(currentRate) + '%');// }//두번째 animate 사용자속성 만들어 넣기 // $({rate:0}).animate({rate:rateNum},{// .. 2024. 7. 17.
hasClass를 이용한 이미지 체인지 var $window = $(window), $header = $('.header'), $logo = 'img/logo.svg', $mlogo = 'img/mlogo.svg';$window.scroll($.throttle(1000/15, function(){ if ($(this).scrollTop() >= 100 ){ if(!$header.hasClass('small')){ $header.addClass('small'); switchLogo($mlogo); } } else { if($header.hasClass('small')){ $header.removeClass('small');.. 2024. 7. 17.
throttle(), clone() var $window = $(window), $header = $('.header'), $haderClone = $header.contents().clone(), $headerCloneContainer = $(''), $threshold = $header.offset().top + $header.outerHeight();$headerCloneContainer.append($haderClone);$headerCloneContainer.appentTo('body');$window.scroll($.throttle(1000/15, function(){ if ($(this).scrollTop() >= $threshold ){ $headerCloneContainer.addCl.. 2024. 7. 17.
lottieFiles https://lottiefiles.com/interactivity Lottie Player - Interactivity GuideThis is a quick demo for using the Lottie interactivity library with the Lottie Web Player component and the Lottie Player to add interactivity to your applicationslottiefiles.com    스크롤 LottieInteractivity.create({ player: '#test', mode: 'scroll', actions: [ { visibility:[0.2, 0.7], //컨테이너의 20.. 2024. 7. 15.
Lottie.js, scroll 연동 사용법 : https://airbnb.io/lottie/#/1. 에프터이펙트에서 제작한 애니를 json으로 변환한다. bodymovin 플러그인이 파일을 인식 못하고 작동이 안되어 찾아봤더니 lottieFiles 가 생기면서 이제는 lottieFiles 플러그인으로 대체되었다고 한다. https://lottiefiles.com/kr/ 무료 로티 애니메이션, 모션 그래픽을 위한 모든 플러그인과 도구를 한 곳에 - 로티파일즈/LottieFi로티파일즈/LottieFiles는 오픈소스 애니메이션 포맷 로티를 제공하는 세상에서 가장 큰 무료 플랫폼입니다. 웹, iOS, 안드로이드, 윈도우를 위한 모션 그래픽 작업을 지원하는 플러그인과 툴을 통lottiefiles.com 기본 작동법let clickAni = doc.. 2024. 7. 15.
swiper.on('slideChange'), letters const swiper = new Swiper('.swiper', { mousewheel: true, direction: 'vertical', speed: 1700, parallax: true});//글자 한자씩 쪼개기 document.querySelectorAll('.header-content h1').forEach(e => { e.innerHTML = e.textContent.replace(/ (-|#|@){1}/g, s => s[1]+s[0]).replace(/(\S*)/g, m => { return m.replace(/\S(-|#|@)?/g, '$&') }) e.querySelectorAll('.letter').forEach(function(l, i) { l.setAttribute('style.. 2024. 7. 14.
gsap, draggable, photoswipe window.onload = function() { setTimeout(function() { document.body.classList.add('loaded') if (window.matchMedia('(min-width: 992px)').matches) { // If not mobile Draggable.create('.gallery', { bounds: 'body', inertia: true }) } }, 200)}// 이미지 링크 주소 가져오기 document.querySelectorAll('.gallery__item').forEach(function(e) { let img = new Image(), hrefURL = e.getAttribute('href') img.on.. 2024. 7. 10.
백그라운드 영상과 swiper 연계 const video = document.querySelector('.video-background')const swiperText = new Swiper('.swiper', { speed: 1600, loop:true, mousewheel: { }, pagination: { el: '.swiper-pagination', clickable: true }, navigation: { prevEl: '.swiper-button-prev', nextEl: '.swiper-button-next' }})swiperText.on('slideChange', function() { gsap.to(video, 1.6, { currentTime: (video.duration / (this.slides.len.. 2024. 7. 9.
page transition var $context = $('body'),$navItem = $('#main-nav-menu li'),$navItemMenu = $('#main-nav-menu li a'),$navUnderline = $('#nav-underline'),$activeItem = $('#main-nav-menu li.active'),animating = false;$navUnderline.css({ left: $activeItem.position().left, width: $activeItem.outerWidth(), });$navItem.mouseenter(function(){ $navUnderline.stop().css({ left: $(this).position().left, .. 2024. 7. 9.
setProperty('--scrollTop', `${this.scrollY}px`) window.addEventListener('scroll', e => { document.documentElement.style.setProperty('--scrollTop', `${this.scrollY}px`) // Update method})gsap.registerPlugin(ScrollTrigger, ScrollSmoother)ScrollSmoother.create({ wrapper: '.wrapper', content: '.content'}).layers__base { transform: translate3d(0, calc(var(--scrollTop) / 1.6), 0); z-index: 0;}.layers__middle { transform: translate3d(0, calc(var(--s.. 2024. 7. 9.
appendChild(), prepend() let next = document.querySelector('.next');let prev = document.querySelector('.prev');let slider = document.querySelector('.slider');function append(){ let slides = document.querySelectorAll('.slides'); slider.appendChild(slides[0]);}function prepend(){ let slides = document.querySelectorAll('.slides'); slider.prepend(slides[slides.length - 1]);}next.addEventListener('click', funct.. 2024. 7. 8.
transform-style: preserve-3d, Object.assign(), 비효과 document.addEventListener('mousemove', e => { Object.assign(document.documentElement, { style: ` --move-x: ${(e.clientX - window.innerWidth / 2) * -.01}deg; --move-y: ${(e.clientY - window.innerHeight / 2) * .01}deg; ` })}) H1 Main Title HTML / CSS small text .. 2024. 7. 7.
horizon parallax, particle new Swiper(".slider", { //direction:"vertical", speed:2000, mousewheel: { enabled:true, sensitivity:2.4, }, spaceBetween: 18, parallax:true, //freeMode:true}):root{ --transition:1.5s cubic-bezier(0.2, 0.6, 0, 1) ;}.slider {height: 100%;}.slider__layer{position: absolute; /* transition: var(--transition) !important; */ inset:0; background-size: cove.. 2024. 7. 6.
swiper bind document.querySelectorAll(".slider").forEach((n, i) => { window[`slider${i+1}`] = new Swiper(n, { freeMode:true, centeredSlides:true, direction:"vertical", mousewheel:true, slidesPerView:1.75, slidesOffsetBefore: -125, })})bindSwipers(slider1, slider2, slider3, slider4); .. 2024. 7. 6.
gsap+smoothScroll gsap.registerPlugin(ScrollTrigger, ScrollSmoother);if(ScrollTrigger.isTouch !==1){ ScrollSmoother.create({ wrapper:".wrapper", content:'.content', smooth:1.5, effects:true })}//topgsap.fromTo(".hero-section", { opacity:1}, { opacity: 0, scrollTrigger: { trigger: ".hero-section", start: "center", end: "820", scrub: true }})/.. 2024. 7. 6.
gsap vertical .s2ul{display: flex; gap: 30px; align-items: start; position: absolute; left: 30%;}.s2ul li{position: relative; display: flex; align-items: center; justify-content: center; background-image: url(img/1.jpg); background-size: cover; margin-bottom: 50px; width:400px; height: 350px; }.s2ul li a{display: block; background-color:black; color: #fff; font-size: 2rem; padding: 5px 25px;}.s2ul li{clip-p.. 2024. 7. 5.
scrolla plugin https://maximzhurkin.github.io/jquery-scrolla/ Scrolla - jQuery plugin for reveal animations when scrollingInclude animate.css Include jQuery and jquery-scrolla Add html Initialize plugin $(document).ready(function(){ $('.animate').scrolla(); }); Custom settings $('.animate').scrolla({ // default mobile: false, // disable animation on mobiles once: false, // onmaximzhurkin.github.io  card111.. 2024. 7. 5.
gsap toArray, forEach gsap 배열 반복 gsap.utils.toArray(".s2ul li").forEach(function(card){ }).s2 ul{display: flex; gap: 30px;flex-direction: column; }.s2 ul li{position: relative; display: flex; align-items: center; justify-content: center; background-image: url(img/1.jpg); margin-bottom: 50px; width:300px; height: 350px; overflow: hidden; }.s2 ul li::before{content: '';width: 100%; height: 100%; background-col.. 2024. 7. 5.
gsap2 .s4 .round{position: absolute; top: 40%; left:50%; transform: translateX(-50%); display: block; width: 1500px; height: 1500px; border-radius: 50%; background-color: chocolate; z-index: 1;}$(function(){ gsap.registerPlugin(ScrollTrigger); gsap.timeline({ scrollTrigger:{ trigger: '.s4', start: "top 50%", end : "30% 0%", scrub:1, .. 2024. 7. 5.
gsap 1 $(function(){ gsap.registerPlugin(ScrollTrigger); gsap.timeline({ scrollTrigger:{ trigger: ".s2ul", //대상 start: "top 90%", //대상의 탑과 브라우저의 90%가 만날때 end: "50% 100%" , scrub: 1, //빠르기 markers:true, } }) // to :0% ~ 100% 진행, from은 -100% - 0% 진행, fromto -100% ~ 100% 전체, set 순식간에 .to('.s2ul li:nth-child(1)', {y:"-300.. 2024. 7. 5.
scroll let lastScrollTop = 0;gnb = document.getElementById('gnb');window.addEventListener("scroll", function(){ let scrollTop = window.pageYOffset || document.documentElement.scrollTop; if(scrollTop > lastScrollTop){ gnb.classList.add('active'); } else { gnb.classList.remove('active'); } lastScrollTop = scrollTop;}) 2024. 7. 4.
scroll, clip-path Scroll animationlet s1 = document.getElementById('s1');let s2 = document.getElementById('s2');window.addEventListener("scroll", function(){ s1.style.left = window.scrollY +'px'; s2.style.left = - window.scrollY + 'px';}).wrap{position: fixed;top: 0; left: 0; width: 100%; height: 100vh; z-index: 100;}.wrap .sbox{position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color:.. 2024. 7. 4.
sort, filter var products = [ { id: 0, price: 5800, title: "학교종이 땡땡" }, { id: 1, price: 3000, title: "동해물과" }, { id: 2, price: 5500, title: "전국노래자랑" },];//가격정렬$(".lowprice").on("click", function () { products.sort(function (a, b) { return a.price - b.price; }); console.log(products); $(".row").html(""); products.forEach(function (a, i) { prodlist(a, i); });});//상품명 역순.. 2024. 7. 1.
ajax var products = [ {id:0, price:5800, title: '학교종이 땡땡'}, {id:1, price:3000, title: '동해물과'}, {id:2, price:5500, title: '전국노래자랑'},]function prodlist(a, i){ var prodbox2 = ` ${a.title} 가격 : ${a.price} `; $('.row').append(prodbox2);}products.forEach(function(a, i){ prodlist(a, i);})var btncount = 0;$('.more').on('click', function(){ btncount += 1; if(btncount == 1){ $.get('https.. 2024. 7. 1.
select, append, forEach select 상품선택 모자 셔츠 95 100 $('.form-select').eq(0).on('input', function(){ var value = $('.form-select').eq(0).val(); // 셀렉트 선택값 if(value == '셔츠'){ $('.form-select').eq(1).removeClass('form-hide'); }})// 축약 $('.form-select').eq(0).on('input', function(e){ var value = e.currentTarget.value; // var value = this.value 와 같음 if(value == '셔츠'){ $('.form-select').eq(1).removeClass('f.. 2024. 7. 1.
array var car = ['소나타', 50000, 'white'];var car2 = { name: '아반떼', price: 3000 };var car3 = { name: '아반떼', price: [2500, 2000, 1000] };$('.name').html(car2.name);$('.price').html(car2['price']);$('.color').html(car[2]);$('.price2').html(car3.price[0]); //할인된 가격 car.sort(); //정렬car.slice(1,3) //1번째부터 3번째 전까지 var products = [ { id : 0, price : 70000, title : 'Blossom Dress' }, { id : 1, price : 50.. 2024. 7. 1.
bubble e.target; //유저가 실제로 누른거e.currentTarget; //이벤트리스너 달린 곳e.preventDefault(); //기본동작막기e.stopPropagation(); //body같은 상위요소 버블링 막기 function tapshow(i) { $(".tab-button").removeClass("orange"); $(".tab-button").eq(i).addClass("orange"); $(".tab-content").removeClass("show"); $(".tab-content").eq(i).addClass("show");}$(".list").click(function (e) { tapshow(e.target.dataset.id);}); Pr.. 2024. 7. 1.