주말에 제 홈피를 리뉴얼 중 (각 div 로 위아래 부드럽게 이동 하는 한장짜리 로 짜봤는데) 문제가 좀 생겼었습니다.
모든 jQuery 는 제가 직접 짠거라서 간단한데 반응형 jQuery 슬라이더를 넣으니 IE 에서 속도문제가 좀 생기는 것 같더라구요.
그래서 페이지가 아래로 이동하는 경우에는 슬라이더 관련 js 와 css 를 제거하고, 반대로 페이지가 상단위로 와 있는 경우는 블로그 페이지 관련 js 와 css 가 자동제거 되는 방식을 구현하려고 했는데....
힘들게 하나 찾은 자스 소스가....
function createjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
return fileref
}
function replacejscssfile(oldfilename, newfilename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
var newelement=createjscssfile(newfilename, filetype)
allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
}
}
}
replacejscssfile("oldscript.js", "newscript.js", "js") //Replace all occurences of "oldscript.js" with "newscript.js"
replacejscssfile("oldstyle.css", "newstyle", "css") //Replace all occurences "oldstyle.css" with "newstyle.css"
푸하하하
이걸 넣으면 페이지가 오히려 더 무거워지는 웃기는 상황발생.
조금더 살펴보니 jQuery 에 .remove !!!!!
$( ).remove(); //이거 한줄이면 끝!!!!!
흡사한 방법으로 이것도 되네요
$.globalEval(js);
아, jQuery 의 위대함이란!!!! ㅋㅋㅋㅋ
댓글 3개
13년 전
저도 분석해가면서 제이쿼리를 짜내려 가고 싶은데 부럽습니다..
3개월된 퍼블리셔에겐 아직 쫒기에 먼 님이네요 ㅎㅎ;;
잘보구 갑니다~~
3개월된 퍼블리셔에겐 아직 쫒기에 먼 님이네요 ㅎㅎ;;
잘보구 갑니다~~
13년 전
jquery 는 신세계죠.ㅎㅎ
takumi22
12년 전
Jquery 참 간결하죠 ㅋ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6230 |
senseme
|
12년 전 | 1057 | |
| 6229 |
senseme
|
12년 전 | 1077 | |
| 6228 | 12년 전 | 4441 | ||
| 6227 |
senseme
|
12년 전 | 1494 | |
| 6226 |
senseme
|
12년 전 | 1641 | |
| 6225 | 12년 전 | 5498 | ||
| 6224 | 12년 전 | 3269 | ||
| 6223 |
kiplayer
|
12년 전 | 2140 | |
| 6222 | 12년 전 | 1301 | ||
| 6221 | 12년 전 | 3490 | ||
| 6220 | 12년 전 | 2512 | ||
| 6219 | 12년 전 | 2227 | ||
| 6218 |
senseme
|
12년 전 | 1841 | |
| 6217 |
senseme
|
12년 전 | 1532 | |
| 6216 |
senseme
|
12년 전 | 1528 | |
| 6215 |
senseme
|
12년 전 | 1283 | |
| 6214 | 12년 전 | 2397 | ||
| 6213 |
senseme
|
12년 전 | 1668 | |
| 6212 |
senseme
|
12년 전 | 1343 | |
| 6211 |
senseme
|
12년 전 | 2429 | |
| 6210 |
senseme
|
12년 전 | 1609 | |
| 6209 | 12년 전 | 2217 | ||
| 6208 | 12년 전 | 3441 | ||
| 6207 | 12년 전 | 1223 | ||
| 6206 |
senseme
|
12년 전 | 2197 | |
| 6205 | 12년 전 | 1035 | ||
| 6204 |
kiplayer
|
12년 전 | 1527 | |
| 6203 |
senseme
|
12년 전 | 2119 | |
| 6202 |
senseme
|
12년 전 | 1752 | |
| 6201 |
senseme
|
12년 전 | 4564 | |
| 6200 |
senseme
|
12년 전 | 2664 | |
| 6199 |
senseme
|
12년 전 | 2829 | |
| 6198 |
senseme
|
12년 전 | 1233 | |
| 6197 |
senseme
|
12년 전 | 8550 | |
| 6196 |
senseme
|
12년 전 | 3340 | |
| 6195 | 12년 전 | 1433 | ||
| 6194 |
|
12년 전 | 1286 | |
| 6193 |
senseme
|
12년 전 | 2693 | |
| 6192 |
senseme
|
12년 전 | 5362 | |
| 6191 |
senseme
|
12년 전 | 3415 | |
| 6190 | 12년 전 | 1342 | ||
| 6189 | 12년 전 | 13495 | ||
| 6188 |
웹디자인되고파
|
12년 전 | 1207 | |
| 6187 | 12년 전 | 621 | ||
| 6186 | 12년 전 | 3932 | ||
| 6185 | 12년 전 | 1472 | ||
| 6184 | 12년 전 | 9377 | ||
| 6183 | 12년 전 | 790 | ||
| 6182 |
senseme
|
12년 전 | 1239 | |
| 6181 |
senseme
|
12년 전 | 3220 | |
| 6180 |
senseme
|
12년 전 | 853 | |
| 6179 |
senseme
|
12년 전 | 1762 | |
| 6178 | 12년 전 | 3631 | ||
| 6177 | 12년 전 | 1064 | ||
| 6176 | 12년 전 | 954 | ||
| 6175 |
senseme
|
12년 전 | 5300 | |
| 6174 |
senseme
|
12년 전 | 1426 | |
| 6173 |
senseme
|
12년 전 | 752 | |
| 6172 |
senseme
|
12년 전 | 2741 | |
| 6171 |
senseme
|
12년 전 | 2483 | |
| 6170 |
senseme
|
12년 전 | 1502 | |
| 6169 |
senseme
|
12년 전 | 2928 | |
| 6168 |
senseme
|
12년 전 | 6535 | |
| 6167 | 12년 전 | 2136 | ||
| 6166 | 12년 전 | 745 | ||
| 6165 |
페이지팩트
|
12년 전 | 1904 | |
| 6164 |
네오soft
|
12년 전 | 1856 | |
| 6163 |
|
12년 전 | 2606 | |
| 6162 | 12년 전 | 590 | ||
| 6161 |
|
12년 전 | 1689 | |
| 6160 | 12년 전 | 767 | ||
| 6159 | 12년 전 | 1777 | ||
| 6158 |
|
12년 전 | 2681 | |
| 6157 |
sa2pan
|
12년 전 | 1244 | |
| 6156 | 12년 전 | 3891 | ||
| 6155 | 12년 전 | 9963 | ||
| 6154 | 12년 전 | 1123 | ||
| 6153 | 12년 전 | 2453 | ||
| 6152 |
생각보다몸이앞서다
|
12년 전 | 2122 | |
| 6151 | 12년 전 | 2975 | ||
| 6150 |
kiplayer
|
12년 전 | 6004 | |
| 6149 |
|
12년 전 | 2645 | |
| 6148 | 12년 전 | 2968 | ||
| 6147 |
hwang007
|
12년 전 | 953 | |
| 6146 |
aqqasdf
|
12년 전 | 769 | |
| 6145 | 12년 전 | 1862 | ||
| 6144 | 12년 전 | 5878 | ||
| 6143 |
smwkd
|
12년 전 | 1462 | |
| 6142 | 12년 전 | 4699 | ||
| 6141 | 12년 전 | 929 | ||
| 6140 | 12년 전 | 4094 | ||
| 6139 | 12년 전 | 1239 | ||
| 6138 | 12년 전 | 1095 | ||
| 6137 |
SugarSkull
|
12년 전 | 1678 | |
| 6136 | 12년 전 | 1307 | ||
| 6135 |
한번잘해보자
|
12년 전 | 561 | |
| 6134 |
프리랜서개발자
|
12년 전 | 536 | |
| 6133 |
basaria
|
12년 전 | 20441 | |
| 6132 | 12년 전 | 505 | ||
| 6131 | 12년 전 | 1084 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기