구글 크롬에서만 작동 확인..

 

a 태그에 하이퍼링크를 달았을 때

기본값은 파란색(#0000EE) , 한번 누른적이 있다면 보라색(#551A8B)으로 뜬다.

기본값을 바꿔보자.

 

/* style.css */

:link { color: #0000EE; }
:visited { color: #551A8B; }

 

link 가 링크 방문전 색이고, visited 가 방문한 적이 있는 링크다.

 

 

 

'Frontend > CSS' 카테고리의 다른 글

CSS 애니메이션 성능 최적화하기  (8) 2021.04.07
[CSS] HTML Video Controls 버튼, 아이콘 숨기기  (15) 2020.03.31

python3 버전 기준으로 작성하였습니다.

 

ipstack api 를 사용하여 사용자의 경도, 위도등을 얻어와보자.

 

1. https://ipstack.com/ 접속

 

메인

 

2. 우측상당 pricing 클릭 

 

무료사용은 1달에 10,000 번의 requests 가 가능하다.

Get free api key 를 눌러 회원가입하자.

 

3. 회원 가입이 완료되었다면 우측상당의 Dashboard 를 클릭한다.

api key

 

자신의 api key 를 볼 수있다. 이제 파이썬으로..

 

4. 코드 작성

import requests
import json

key = 'your api key'
send_url = 'http://api.ipstack.com/check?access_key=' + key
r = requests.get(send_url)
j = json.loads(r.text)
print(j)

# 경도
lon = j['longitude']

# 위도
lat = j['latitude']
print(lon,lat)
{'ip': 'my ip', 'type': 'ipv4', 'continent_code': 'AS', 'continent_name': 'Asia', 'country_code': 'KR', 'country_name': 'South Korea', 'region_code': '26', 'region_name': 'Busan', 'city': 'Busan', 'zip': '-', 'latitude': '위도', 'longitude': '경도', 'location': {'geoname_id': 1838524, 'capital': 'Seoul', 'languages': [{'code': 'ko', 'name': 
'Korean', 'native': '한국어'}], 'country_flag': 'http://assets.ipstack.com/flags/kr.svg', 'country_flag_emoji': '🇰🇷', 'country_flag_emoji_unicode': 'U+1F1F0 U+1F1F7', 'calling_code': '82', 
'is_eu': False}}

 

자신의 ip 와 경도 위도를 얻어올 수 있다.

 

자세한 documentation 은 홈페이지를 참고하자.

https://ipstack.com/documentation

 

API Documentation - ipstack

The ipstack API also offers the ability to request data for multiple IPv4 or IPv6 addresses at the same time. In order to process IP addresses in bulk, simply append multiple comma-separated IP addresses to the API's base URL. JSON: The API response for bu

ipstack.com

 

element.insertAdjacentHTML(position, text);

 

element 에 html 텍스트를 파싱하여 node를 추가한다.

jQuery 의 append() 기능과 비슷하다고 생각하면 된다.

<div id='node'> </div>

<script type="text/javascript">
	var node = document.getElementById("node");
    var span = "<span> Hello World! </span>"

	node.insertAdjacentHTML("beforeend", span);
</script>

결과

 

position 엔 4가지가 있다.

jquery 의 append(), prepend(), before(), after() 과 동일하다. 

node.insertAdjacentHTML("beforebegin", "beforebegin");
node.insertAdjacentHTML("afterbegin", "afterbegin");
node.insertAdjacentHTML("beforeend", "beforeend");
node.insertAdjacentHTML("afterend", "afterend");

 

 

결과

 

현재 jQuery코드를 javascript 로 옮기는 중 의문점..

 

document.addEventListener("DOMContentLoaded", function(event) { 
  //do work
});

 

https://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery

자바스크립트로 난수를 생성해보자.

 

 

Math.random() 을 쓰면 된다.

for (var i = 0; i < 10; i++) {
    console.log(Math.random());
}
    
0.25721506183081844
0.5823201981959083
0.1276669448208927
0.5631301578055086
0.17111868936942853
0.5330896617959899
0.8969996301883194
0.5037203939477015
0.6167480911555299
0.009640469869059975

 

Math.random() 은 0 이상,  1 미만의 값을 Return 한다.

 

만약 정수로 0이상 9이하 의 값을 구하고 싶다면?

 

for (var i = 0; i < 10; i++) {
    console.log(Math.floor(Math.random() * 10));
}


5
6
8
6
0
7
4
8
6
9

 

Math.random() 으로 나온 값에 10을 곱해주고 Math.floor() 로 소수점을 없애주면 된다.

 

시작이 0이 아닌 1로 하고 싶다면

 

for (var i = 0; i < 10; i++) {
    console.log(Math.floor(Math.random() * 10) + 1);
}


2
3
1
7
8
10
3
5
2
6

1이상 10이하의 수가 구해진다.

+ Recent posts