반응형
반응형
성공은 목표까지 능력을 끌어올린 결과이고,
실패는 능력에 맞춰 목표를 낮춘 결과입니다.
목표가 흔들리지 않으면
능력이 늘 목표를 따라갑니다.
-조정민, ‘사람이 선물이다’에서

내 삶에 한계를 설정하면 나는
날마다 도망갈 수 있습니다.
그러나 내 삶의 한계를 인정하지 않으면
날마다 더 높은 곳을 향해 도전할 수 있습니다.
도망이냐? 도전이냐? 선택은 내가 하는 것입니다.

반응형
반응형

지난 저녁 전주생막걸리를 마셨더니만 쉽지 않구나.

 

체조시간 건너뛰고.

배영 2

자유형 1

화장실 갔다가

접영 2

스타트 접/자 3

 

마무리 자유형 2

 

마치고 배영 2

 

술마신 다음날 숨차다.

반응형

'운동일지 > 수영' 카테고리의 다른 글

2012.12.01 수영일지  (0) 2012.12.01
2012.11.29 수영일지  (0) 2012.11.29
2012.11.23 수영일지  (0) 2012.11.23
2012.11.22 수영일지  (0) 2012.11.22
2012.11.21 수영일지  (0) 2012.11.21
반응형

세계대전 Z, 쫄깃 : 메가쑈킹과 쫄깃패밀리의 숭구리당당 제주 정착기

 

세계 대전 Z
국내도서>소설
저자 : 맥스 브룩스(Max Brooks) / 박산호역
출판 : 황금가지 2008.06.12
상세보기

 

쫄깃
국내도서>시/에세이
저자 : 고필헌(메가쑈킹),쫄깃패밀리
출판 : 청어람미디어 2012.11.05
상세보기

반응형
반응형

14 Handy jQuery Code Snippets for Developers

The jQuery dev team has been releasing code updates frequently since the project began. JavaScript developers have never had an easier framework to code on frontend interfaces. For anybody just getting started in web development you can be certain to run into some jQuery code on the web.

I have put together a series of 14 helpful jQuery code snippets you may save and copy to use at your own discretion. These are merely blank templates you can edit to change variables and parameters matching your own script. I’m sure even experienced developers may find some of these snippets beneficial and shaving off time during code sessions.

1. Hover On/Off

$("a").hover(
  function () {
    // code on hover over
  },
  function () {
    // code on away from hover
  }
);

Source

The jQuery hover method is a quick solution for handling these events. You can determine whether the user is just hovering over your element, or if the user is just leaving the hover state. This allows for two custom functions where you can run two distinct sets of code.

2. Prevent Anchor Links from Loading

$("a").on("click", function(e){
  e.preventDefault();
});

Source

When you create JavaScript applications there are plenty of times where you need a link or button to just do nothing. This is often for triggering some type of dynamic effect, such as a hidden menu or Ajax call. By using the event object during any click, we can manipulate the data sent back to the browser URL. In this scenario I am stopping the whole href from loading anything at all!

3. Scroll to Top

$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});

Source

You have probably seen this functionality becoming popular on all the new social networking websites. I have definitely seen this technique appear on infinite-scrolling layouts such as Tumblr and Pinterest.

The code is very minimal but powerful in some layouts. You are offering a simple link or button display which behaves like a “back to home” link. By using the animate effect in jQuery users won’t notice the jump all at once, but instead over a brief period of milliseconds.

4. Ajax Template

$.ajax({
  type: 'POST',
  url: 'backend.php',
  data: "q="+myform.serialize(),
  success: function(data){
    // on success use return data here
  },
  error: function(xhr, type, exception) { 
    // if ajax fails display error alert
    alert("ajax error response type "+type);
  }
});

Source

Passing form data via Ajax is one of the most common uses for jQuery. As a web developer myself I can’t think how many times I am using the ajax method in each project. The syntax can be awfully confusing to memorize, and checking the documentation gets old after a while. Consider copying this small template for usage in any future Ajax-powered webapps.

5. Animate Template

$('p').animate({
    left: '+=90px',
    top: '+=150px',
    opacity: 0.25
  }, 900, 'linear', function() {
    // function code on animation complete
});

Source

As we saw the animate method earlier, this is very powerful for creating dynamic movement on your page. CSS3 transitions are a whole lot easier in some circumstances. But with animate you can manipulate multiple objects or CSS properties all at once!

It’s a very powerful library to get into and start playing with. If you haven’t used any of the jQuery UI library I suggest spending an hour or two practicing with demo stuff. You can animate any object on the page into almost any position or updated style.

6. Toggle CSS Classes

$('nav a').toggleClass('selected');

Source

Adding and removing CSS classes on HTML elements is another fairly common action. This is one technique you may consider with selected menu items, highlighted rows, or active input elements. This newer method is simply quicker than using .addClass() and .removeClass() where you can put all the code into one function call.

7. Toggle Visibility

$("a.register").on("click", function(e){
  $("#signup").fadeToggle(750, "linear");
});

Source

Fading objects out of the document is very common with modern user interfaces. You can always have small popup boxes or notifications which need to display and then hide after a few seconds. Using the fadeToggle function you can quickly hide and display any objects in your DOM. Keep this code handy if you will ever need such functionality in a website interface.

8. Loading External Content

$("#content").load("somefile.html", function(response, status, xhr) {
  // error handling
  if(status == "error") {
    $("#content").html("An error occured: " + xhr.status + " " + xhr.statusText);
  }
});

Source

Believe it or not you can actually pull external HTML code from a file right into your webpage. This doesn’t technically require an Ajax call, but instead we’re parsing the external files for whatever content they have. Afterwards this new content may be loaded into the DOM anywhere in the page.

9. Keystroke Events

$('input').keydown(function(e) {
  // variable e contains keystroke data
  // only accessible with .keydown()
  if(e.which == 11) {
     e.preventDefault();
  }
});

$('input').keyup(function(event) {
  // run other event codes here							  
});

Source

Dealing with user input is another grey area I have come across. The jQuery keydown and keyup event listeners are perfect for dealing with such experiences. Both of these methods are called at very different times during the keystroke event. So make sure you have the application planned out before deciding which one to use.

10. Equal Column Heights

var maxheight = 0;
$("div.col").each(function(){
  if($(this).height() > maxheight) { maxheight = $(this).height(); }
});

$("div.col").height(maxheight);

Source

This is a small jQuery snippet I ran into while surfing the web earlier in the year. While this is not the most recommended solution for your layout display, this code snippet may come in handy down the line. CSS column heights are not always matched and so this dynamic solution using JavaScript is worthy of some insight.

11. Append New HTML

var sometext = "here is more HTML";
$("p#text1").append(sometext); // added after
$("p#text1").prepend(sometext); // added before

Source

Using the .append() method we can quickly place any HTML code directly into the DOM. This is similar to .load() we saw earlier, except these functions can take HTML from any source. You could setup a brand new variable of HTML text or even clone HTML right from your webpage. These properties are often used in conjunction with Ajax response data.

12. Setting & Getting Attributes

var alink = $("a#user").attr("href"); // obtain href attribute value
$("a#user").attr("href", "http://www.google.com/"); // set the href attribute to a new value
$("a#user").attr({
  alt: "the classiest search engine",
  href: "http://www.google.com/"
}); // set more than one attribute to new values

Source

This property is relatively straightforward but I always see these problems in StackOverflow. You can pull the .attr() method on any HTML element and pass in the attribute string value. This will return the value of that attribute, whether it’s ID or class or name or maxlength. All HTML attributes may be accessed through this syntax and so it’s a very powerful method to keep in mind.

13. Retrieve Content Values

$("p").click(function () {
  var htmlstring = $(this).html(); // obtain html string from paragraph
  $(this).text(htmlstring); // overwrite paragraph text with new string value
});
	
var value1 = $('input#username').val(); // textfield input value
var value2 = $('input:checkbox:checked').val(); // get the value from a checked checkbox
var value3 = $('input:radio[name=bar]:checked').val(); // get the value from a set of radio buttons

Source

Instead of appending new HTML content into the document you may also pull out the current HTML content from any area in your webpage. This can be an entire list item block, or the contents of a paragraph tag. Also the .val() property is used on input fields and form elements where you cannot get inside the object to read anything further.

14. Traversing the DOM

$("div#home").prev("div"); // find the div previous in relation to the current div
$("div#home").next("ul"); // find the next ul element after the current div
$("div#home").parent(); // returns the parent container element of the current div
$("div#home").children("p"); // returns only the paragraphs found inside the current div

Source

This idea of traversing through object nodes is deep enough to be an article within itself. But for any intermediate or advance jQuery developers who understand this topic, I’m sure these quick snippets will help in future problem solving.

The goal is often to pull data from another element related to the currently active element(clicked, hovered, etc). This could be the container(parent) element or another inner(child) element, too. There are lots of tools for pulling data from around the DOM so don’t be afraid of experimentation.



 

반응형
반응형
장애물을 만나면 이렇게 생각하라.
"내가 너무 일찍 포기하는 것이 아닌가?"
실패한 사람들이 '현명하게' 포기할 때,
성공한 사람들은 '미련하게' 참는다.
-마크 피셔, ‘스피릿/부자를 만드는 영혼의 힘’에서

‘힘겨운 상황에 처하고 모든 게 장애로 느껴질 때,
단 1분 조차도 더는 견딜 수 없다고 느껴질 때,
그때야말로 결코 포기하지 마십시오.
바로 그런 시점과 위치에서 상황은 바뀌기 시작합니다.’
(해리엇 비처 스토우)
동트기 직전이 가장 어두운 법입니다.

반응형
반응형
재키는
어떤 스타일이 유행하더라도
자기한테 어울리지 않는다고 생각하면
거부할 줄 알았고, 조금이라도 자신이 없는 일은
누가 뭐래도 거들떠보지 않았다. 우리도
내면의 목소리에 귀를 기울이면
최선의 길을 찾을 수 있다.


- 티나 산티 플래허티의《워너비 재키》중에서 -


* 우리에게 '강남 스타일'이 있다면
미국에는 한때 '재키 스타일'이 있었습니다.
깊은산속 옹달샘에는 '옹달샘 스타일'이 있고요.
누구에게나 그 사람만의 '자기 스타일'이 있습니다.
유행에 흔들리지 않고 자기 내면의 깊은 목소리에
귀를 기울이면 자기 스타일을 만들 수 있습니다.
그 자기 스타일이 많은 사람들에게
즐거움과 희망과 감동을
안겨줄 수 있습니다.

반응형

'아침편지' 카테고리의 다른 글

'더러움'을 씻어내자  (0) 2012.11.28
'놀란 어린아이'처럼  (0) 2012.11.27
냉정한 배려  (0) 2012.11.24
돌풍이 몰아치는 날  (0) 2012.11.23
더 넓은 공간으로  (0) 2012.11.22

+ Recent posts