찾다
웹 프론트엔드JS 튜토리얼Sina의 라이트박스 효과. _형태 효과

사용할 때는 A 태그에 rel="lightbox"를 추가하면 됩니다. 예:
Sina의 라이트박스 효과. _형태 효과

저도 직접 작성했는데 두 개의 모듈이 포함되어 있습니다(func.js 공용 라이브러리 및 ImagesLoader.js 이미지 로딩 클래스). 잠시 후.
HTML #overlay {
FILTER: Alpha(opacity=50) BACKGROUND-IMAGE: url(images/blank.gif): #000
}
Sina의 라이트박스 효과. _형태 효과

<script> <BR><!--// <BR>function addEvent(object, type, handler) <BR>{ <BR> if (object.addEventListener) { <BR> object.addEventListener(type, handler, false); <BR> } else if (object.attachEvent) { <BR> object.attachEvent(['on',type].join(''),handler); <BR> } else { <BR> object[['on',type].join('')] = handler; <BR> } <BR>} <BR>function WindowSize() <BR>{ // window size object <BR> this.w = 0; <BR> this.h = 0; <BR> return this.update(); <BR>} <BR>WindowSize.prototype.update = function() <BR>{ <BR> var d = document; <BR> this.w = <BR> (window.innerWidth) ? window.innerWidth <BR> : (d.documentElement && d.documentElement.clientWidth) ? d.documentElement.clientWidth <BR> : d.body.clientWidth; <BR> this.h = <BR> (window.innerHeight) ? window.innerHeight <BR> : (d.documentElement && d.documentElement.clientHeight) ? d.documentElement.clientHeight <BR> : d.body.clientHeight; <BR> return this; <BR>}; <BR>function PageSize() <BR>{ // page size object <BR> this.win = new WindowSize(); <BR> this.w = 0; <BR> this.h = 0; <BR> return this.update(); <BR>} <BR>PageSize.prototype.update = function() <BR>{ <BR> var d = document; <BR> this.w = <BR> (window.innerWidth && window.scrollMaxX) ? window.innerWidth + window.scrollMaxX <BR> : (d.body.scrollWidth > d.body.offsetWidth) ? d.body.scrollWidth <BR> : d.body.offsetWidt; <BR> this.h = <BR> (window.innerHeight && window.scrollMaxY) ? window.innerHeight + window.scrollMaxY <BR> : (d.body.scrollHeight > d.body.offsetHeight) ? d.body.scrollHeight <BR> : d.body.offsetHeight; <BR> this.win.update(); <BR> if (this.w < this.win.w) this.w = this.win.w; <BR> if (this.h < this.win.h) this.h = this.win.h; <BR> return this; <BR>}; <BR>function PagePos() <BR>{ // page position object <BR> this.x = 0; <BR> this.y = 0; <BR> return this.update(); <BR>} <BR>PagePos.prototype.update = function() <BR>{ <BR> var d = document; <BR> this.x = <BR> (window.pageXOffset) ? window.pageXOffset <BR> : (d.documentElement && d.documentElement.scrollLeft) ? d.documentElement.scrollLeft <BR> : (d.body) ? d.body.scrollLeft <BR> : 0; <BR> this.y = <BR> (window.pageYOffset) ? window.pageYOffset <BR> : (d.documentElement && d.documentElement.scrollTop) ? d.documentElement.scrollTop <BR> : (d.body) ? d.body.scrollTop <BR> : 0; <BR> return this; <BR>}; <BR>function UserAgent() <BR>{ // user agent information <BR> var ua = navigator.userAgent; <BR> this.isWinIE = this.isMacIE = false; <BR> this.isGecko = ua.match(/Gecko\//); <BR> this.isSafari = ua.match(/AppleWebKit/); <BR> this.isOpera = window.opera; <BR> if (document.all && !this.isGecko && !this.isSafari && !this.isOpera) { <BR> this.isWinIE = ua.match(/Win/); <BR> this.isMacIE = ua.match(/Mac/); <BR> this.isNewIE = (ua.match(/MSIE 5\.5/) || ua.match(/MSIE 6\.0/)); <BR> } <BR> return this; <BR>} <BR>// === lightbox === <BR>function LightBox(option) <BR>{ <BR> var self = this; <BR> self._imgs = new Array(); <BR> self._wrap = null; <BR> self._box = null; <BR> self._open = -1; <BR> self._page = new PageSize(); <BR> self._pos = new PagePos(); <BR> self._ua = new UserAgent(); <BR> self._expandable = false; <BR> self._expanded = false; <BR> self._expand = option.expandimg; <BR> self._shrink = option.shrinkimg; <BR> return self._init(option); <BR>} <BR>LightBox.prototype = { <BR> _init : function(option) <BR> { <BR> var self = this; <BR> var d = document; <BR> if (!d.getElementsByTagName) return; <BR> var links = d.getElementsByTagName("a"); <BR> for (var i=0;i<links.length;i++) { <BR> var anchor = links[i]; <BR> var num = self._imgs.length; <BR> if (!anchor.getAttribute("href") <BR> || anchor.getAttribute("rel") != "lightbox") continue; <BR> // initialize item <BR> self._imgs[num] = {src:anchor.getAttribute("href"),w:-1,h:-1,title:'',cls:anchor.className}; <BR> if (anchor.getAttribute("title")) <BR> self._imgs[num].title = anchor.getAttribute("title"); <BR> else if (anchor.firstChild && anchor.firstChild.getAttribute && anchor.firstChild.getAttribute("title")) <BR> self._imgs[num].title = anchor.firstChild.getAttribute("title"); <BR> anchor.onclick = self._genOpener(num); // set closure to onclick event <BR> } <BR> var body = d.getElementsByTagName("body")[0]; <BR> self._wrap = self._createWrapOn(body,option.loadingimg); <BR> self._box = self._createBoxOn(body,option); <BR> return self; <BR> }, <BR> _genOpener : function(num) <BR> { <BR> var self = this; <BR> return function() { self._show(num); return false; } <BR> }, <BR> _createWrapOn : function(obj,imagePath) <BR> { <BR> var self = this; <BR> if (!obj) return null; <BR> // create wrapper object, translucent background <BR> var wrap = document.createElement('div'); <BR> wrap.id = 'overlay'; <BR> with (wrap.style) { <BR> display = 'none'; <BR> position = 'fixed'; <BR> top = '0px'; <BR> left = '0px'; <BR> zIndex = '50'; <BR> width = '100%'; <BR> height = '100%'; <BR> } <BR> if (self._ua.isWinIE) wrap.style.position = 'absolute'; <BR> addEvent(wrap,"click",function() { self._close(); }); <BR> obj.appendChild(wrap); <BR> // create loading image, animated image <BR> var imag = new Image; <BR> imag.onload = function() { <BR> var spin = document.createElement('img'); <BR> spin.id = 'loadingImage'; <BR> spin.src = imag.src; <BR> spin.style.position = 'relative'; <BR> self._set_cursor(spin); <BR> addEvent(spin,'click',function() { self._close(); }); <BR> wrap.appendChild(spin); <BR> imag.onload = function(){}; <BR> }; <BR> if (imagePath != '') imag.src = imagePath; <BR> return wrap; <BR> }, <BR> _createBoxOn : function(obj,option) <BR> { <BR> var self = this; <BR> if (!obj) return null; <BR> // create lightbox object, frame rectangle <BR> var box = document.createElement('div'); <BR> box.id = 'lightbox'; <BR> with (box.style) { <BR> display = 'none'; <BR> position = 'absolute'; <BR> zIndex = '60'; <BR> } <BR> obj.appendChild(box); <BR> // create image object to display a target image <BR> var img = document.createElement('img'); <BR> img.id = 'lightboxImage'; <BR> self._set_cursor(img); <BR> addEvent(img,'click',function(){ self._close(); }); <BR> addEvent(img,'mouseover',function(){ self._show_action(); }); <BR> addEvent(img,'mouseout',function(){ self._hide_action(); }); <BR> box.appendChild(img); <BR> var zoom = document.createElement('img'); <BR> zoom.id = 'actionImage'; <BR> with (zoom.style) { <BR> display = 'none'; <BR> position = 'absolute'; <BR> top = '15px'; <BR> left = '15px'; <BR> zIndex = '70'; <BR> } <BR> self._set_cursor(zoom); <BR> zoom.src = self._expand; <BR> addEvent(zoom,'mouseover',function(){ self._show_action(); }); <BR> addEvent(zoom,'click', function() { self._zoom(); }); <BR> box.appendChild(zoom); <BR> addEvent(window,'resize',function(){ self._set_size(true); }); <BR> // close button <BR> if (option.closeimg) { <BR> var btn = document.createElement('img'); <BR> btn.id = 'closeButton'; <BR> with (btn.style) { <BR> display = 'inline'; <BR> position = 'absolute'; <BR> right = '10px'; <BR> top = '10px'; <BR> width = '15px'; <BR> height = '15px'; <BR> zIndex = '80'; <BR> } <BR> btn.src = option.closeimg; <BR> self._set_cursor(btn); <BR> addEvent(btn,'click',function(){ self._close(); }); <BR> box.appendChild(btn); <BR> } <BR> // caption text <BR> var caption = document.createElement('span'); <BR> caption.id = 'lightboxCaption'; <BR> with (caption.style) { <BR> display = 'none'; <BR> position = 'absolute'; <BR> zIndex = '80'; <BR> } <BR> box.appendChild(caption); <BR> // create effect image <BR> if (!option.effectpos) option.effectpos = {x:0,y:0}; <BR> else { <BR> if (option.effectpos.x == '') option.effectpos.x = 0; <BR> if (option.effectpos.y == '') option.effectpos.y = 0; <BR> } <BR> var effect = new Image; <BR> effect.onload = function() { <BR> var effectImg = document.createElement('img'); <BR> effectImg.id = 'effectImage'; <BR> effectImg.src = effect.src; <BR> if (option.effectclass) effectImg.className = option.effectclass; <BR> with (effectImg.style) { <BR> position = 'absolute'; <BR> display = 'none'; <BR> left = [option.effectpos.x,'px'].join('');; <BR> top = [option.effectpos.y,'px'].join(''); <BR> zIndex = '90'; <BR> } <BR> self._set_cursor(effectImg); <BR> addEvent(effectImg,'click',function() { effectImg.style.display = 'none'; }); <BR> box.appendChild(effectImg); <BR> }; <BR> if (option.effectimg != '') effect.src = option.effectimg; <BR> return box; <BR> }, <BR> _set_photo_size : function() <BR> { <BR> var self = this; <BR> if (self._open == -1) return; <BR> var imag = self._box.firstChild; <BR> var targ = { w:self._page.win.w - 30, h:self._page.win.h - 30 }; <BR> var orig = { w:self._imgs[self._open].w, h:self._imgs[self._open].h }; <BR> // shrink image with the same aspect <BR> var ratio = 1.0; <BR> if ((orig.w >= targ.w || orig.h >= targ.h) && orig.h && orig.w) <br><br> ratio = ((targ.w / orig.w) < (targ.h / orig.h)) ? targ.w / orig.w : targ.h / orig.h; <BR> imag.width = Math.floor(orig.w * ratio); <BR> imag.height = Math.floor(orig.h * ratio); <BR> self._expandable = (ratio < 1.0) ? true : false; <BR> if (self._ua.isWinIE) self._box.style.display = "block"; <BR> self._box.style.top = [self._pos.y + (self._page.win.h - imag.height - 30) / 2,'px'].join(''); <BR> self._box.style.left = [((self._page.win.w - imag.width - 30) / 2),'px'].join(''); <BR> self._show_caption(true); <BR> }, <BR> _set_size : function(onResize) <BR> { <BR> var self = this; <BR> if (self._open == -1) return; <BR> self._page.update(); <BR> self._pos.update(); <BR> var spin = self._wrap.firstChild; <BR> if (spin) { <BR> var top = (self._page.win.h - spin.height) / 2; <BR> if (self._wrap.style.position == 'absolute') top += self._pos.y; <BR> spin.style.top = [top,'px'].join(''); <BR> spin.style.left = [(self._page.win.w - spin.width - 30) / 2,'px'].join(''); <BR> } <BR> if (self._ua.isWinIE) { <BR> self._wrap.style.width = [self._page.win.w,'px'].join(''); <BR> self._wrap.style.height = [self._page.h,'px'].join(''); <BR> } <BR> if (onResize) self._set_photo_size(); <BR> }, <BR> _show_action : function() <BR> { <BR> var self = this; <BR> if (self._open == -1 || !self._expandable) return; <BR> var obj = document.getElementById('actionImage'); <BR> if (!obj) return; <BR> obj.src = (self._expanded) ? self._shrink : self._expand; <BR> obj.style.display = 'inline'; <BR> }, <BR> _hide_action : function() <BR> { <BR> var self = this; <BR> var obj = document.getElementById('actionImage'); <BR> if (obj) obj.style.display = 'none'; <BR> }, <BR> _zoom : function() <BR> { <BR> var self = this; <BR> if (self._expanded) { <BR> self._set_photo_size(); <BR> self._expanded = false; <BR> } else if (self._open > -1) { <BR> var imag = self._box.firstChild; <BR> self._box.style.top = [self._pos.y,'px'].join(''); <BR> self._box.style.left = '0px'; <BR> imag.width = self._imgs[self._open].w; <BR> imag.height = self._imgs[self._open].h; <BR> self._show_caption(false); <BR> self._expanded = true; <BR> } <BR> self._show_action(); <BR> }, <BR> _show_caption : function(enable) <BR> { <BR> var self = this; <BR> var caption = document.getElementById('lightboxCaption'); <BR> if (!caption) return; <BR> if (caption.innerHTML.length == 0 || !enable) { <BR> caption.style.display = 'none'; <BR> } else { // now display caption <BR> var imag = self._box.firstChild; <BR> with (caption.style) { <BR> top = [imag.height + 10,'px'].join(''); // 10 is top margin of lightbox <BR> left = '0px'; <BR> width = [imag.width + 20,'px'].join(''); // 20 is total side margin of lightbox <BR> height = '1.2em'; <BR> display = 'block'; <BR> } <BR> } <BR> }, <BR> _show : function(num) <BR> { <BR> var self = this; <BR> var imag = new Image; <BR> if (num < 0 || num >= self._imgs.length) return; <BR> var loading = document.getElementById('loadingImage'); <BR> var caption = document.getElementById('lightboxCaption'); <BR> var effect = document.getElementById('effectImage'); <BR> self._open = num; // set opened image number <BR> self._set_size(false); // calc and set wrapper size <BR> self._wrap.style.display = "block"; <BR> if (loading) loading.style.display = 'inline'; <BR> imag.onload = function() { <BR> if (self._imgs[self._open].w == -1) { <BR> // store original image width and height <BR> self._imgs[self._open].w = imag.width; <BR> self._imgs[self._open].h = imag.height; <BR> } <BR> if (effect) { <BR> effect.style.display = (!effect.className || self._imgs[self._open].cls == effect.className) <BR> ? 'block' : 'none'; <BR> } <BR> if (caption) caption.innerHTML = self._imgs[self._open].title; <BR> self._set_photo_size(); // calc and set lightbox size <BR> self._hide_action(); <BR> self._box.style.display = "block"; <BR> self._box.firstChild.src = imag.src; <BR> self._box.firstChild.setAttribute('title',self._imgs[self._open].title); <BR> if (loading) loading.style.display = 'none'; <BR> }; <BR> self._expandable = false; <BR> self._expanded = false; <BR> imag.src = self._imgs[self._open].src; <BR> }, <BR> _set_cursor : function(obj) <BR> { <BR> var self = this; <BR> if (self._ua.isWinIE && !self._ua.isNewIE) return; <BR> obj.style.cursor = 'pointer'; <BR> }, <BR> _close : function() <BR> { <BR> var self = this; <BR> self._open = -1; <BR> self._hide_action(); <BR> self._wrap.style.display = "none"; <BR> self._box.style.display = "none"; <BR> } <BR>}; <BR>// === main === <BR>addEvent(window,"load",function() { <BR> var lightbox = new LightBox({ <BR> loadingimg:'http://image2.sina.com.cn/dy/news/2006/0618/images/loading.gif', <BR> expandimg:'http://image2.sina.com.cn/dy/news/2006/0618/images/expand.gif', <BR> shrinkimg:'http://image2.sina.com.cn/dy/news/2006/0618/images/shrink.gif', <BR> effectimg:'images/zzoop.gif', <BR> effectpos:{x:-40,y:-20}, <BR> effectclass:'images/effectable', <BR> closeimg:'http://image2.sina.com.cn/dy/news/2006/0618/images/close.gif' <BR> }); <BR>}); <BR>//--> <BR></script> 뒤로가려면 여기를 클릭하세요. 돌아가려면 클릭하세요

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
JavaScript로 문자열 문자를 교체하십시오JavaScript로 문자열 문자를 교체하십시오Mar 11, 2025 am 12:07 AM

JavaScript 문자열 교체 방법 및 FAQ에 대한 자세한 설명 이 기사는 JavaScript에서 문자열 문자를 대체하는 두 가지 방법 인 내부 JavaScript 코드와 웹 페이지의 내부 HTML을 탐색합니다. JavaScript 코드 내부의 문자열을 교체하십시오 가장 직접적인 방법은 대체 () 메소드를 사용하는 것입니다. str = str.replace ( "find", "replace"); 이 메소드는 첫 번째 일치 만 대체합니다. 모든 경기를 교체하려면 정규 표현식을 사용하고 전역 플래그 g를 추가하십시오. str = str.replace (/fi

자신의 Ajax 웹 응용 프로그램을 구축하십시오자신의 Ajax 웹 응용 프로그램을 구축하십시오Mar 09, 2025 am 12:11 AM

그래서 여기 당신은 Ajax라는이 일에 대해 배울 준비가되어 있습니다. 그러나 정확히 무엇입니까? Ajax라는 용어는 역동적이고 대화식 웹 컨텐츠를 만드는 데 사용되는 느슨한 기술 그룹을 나타냅니다. 원래 Jesse J에 의해 만들어진 Ajax라는 용어

내 자신의 JavaScript 라이브러리를 어떻게 작성하고 게시합니까?내 자신의 JavaScript 라이브러리를 어떻게 작성하고 게시합니까?Mar 18, 2025 pm 03:12 PM

기사는 JavaScript 라이브러리 작성, 게시 및 유지 관리, 계획, 개발, 테스트, 문서 및 홍보 전략에 중점을 둡니다.

브라우저에서 성능을 위해 JavaScript 코드를 최적화하려면 어떻게해야합니까?브라우저에서 성능을 위해 JavaScript 코드를 최적화하려면 어떻게해야합니까?Mar 18, 2025 pm 03:14 PM

이 기사는 브라우저에서 JavaScript 성능을 최적화하기위한 전략에 대해 설명하고 실행 시간을 줄이고 페이지로드 속도에 미치는 영향을 최소화하는 데 중점을 둡니다.

jQuery 매트릭스 효과jQuery 매트릭스 효과Mar 10, 2025 am 12:52 AM

매트릭스 영화 효과를 페이지에 가져 오십시오! 이것은 유명한 영화 "The Matrix"를 기반으로 한 멋진 jQuery 플러그인입니다. 플러그인은 영화에서 클래식 그린 캐릭터 효과를 시뮬레이션하고 사진을 선택하면 플러그인이 숫자로 채워진 매트릭스 스타일 사진으로 변환합니다. 와서 시도해보세요. 매우 흥미 롭습니다! 작동 방식 플러그인은 이미지를 캔버스에로드하고 픽셀 및 색상 값을 읽습니다. data = ctx.getImageData (x, y, settings.grainsize, settings.grainsize) .data 플러그인은 그림의 직사각형 영역을 영리하게 읽고 jQuery를 사용하여 각 영역의 평균 색상을 계산합니다. 그런 다음 사용하십시오

브라우저 개발자 도구를 사용하여 JavaScript 코드를 효과적으로 디버그하려면 어떻게해야합니까?브라우저 개발자 도구를 사용하여 JavaScript 코드를 효과적으로 디버그하려면 어떻게해야합니까?Mar 18, 2025 pm 03:16 PM

이 기사는 브라우저 개발자 도구를 사용하여 효과적인 JavaScript 디버깅, 중단 점 설정, 콘솔 사용 및 성능 분석에 중점을 둡니다.

간단한 jQuery 슬라이더를 만드는 방법간단한 jQuery 슬라이더를 만드는 방법Mar 11, 2025 am 12:19 AM

이 기사에서는 jQuery 라이브러리를 사용하여 간단한 사진 회전 목마를 만들도록 안내합니다. jQuery를 기반으로 구축 된 BXSLIDER 라이브러리를 사용하고 회전 목마를 설정하기위한 많은 구성 옵션을 제공합니다. 요즘 그림 회전 목마는 웹 사이트에서 필수 기능이되었습니다. 한 사진은 천 단어보다 낫습니다! 그림 회전 목마를 사용하기로 결정한 후 다음 질문은 그것을 만드는 방법입니다. 먼저 고품질 고해상도 사진을 수집해야합니다. 다음으로 HTML과 일부 JavaScript 코드를 사용하여 사진 회전 목마를 만들어야합니다. 웹에는 다양한 방식으로 회전 목마를 만드는 데 도움이되는 라이브러리가 많이 있습니다. 오픈 소스 BXSLIDER 라이브러리를 사용할 것입니다. BXSLIDER 라이브러리는 반응 형 디자인을 지원 하므로이 라이브러리로 제작 된 회전 목마는

Angular로 CSV 파일을 업로드하고 다운로드하는 방법Angular로 CSV 파일을 업로드하고 다운로드하는 방법Mar 10, 2025 am 01:01 AM

데이터 세트는 API 모델 및 다양한 비즈니스 프로세스를 구축하는 데 매우 필수적입니다. 그렇기 때문에 CSV 가져 오기 및 내보내기가 자주 필요한 기능인 이유입니다.이 자습서에서는 각도 내에서 CSV 파일을 다운로드하고 가져 오는 방법을 배웁니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경