Skip to content

Instantly share code, notes, and snippets.

View okuden-labo's full-sized avatar

Toshihiro Okuda okuden-labo

View GitHub Profile
@okuden-labo
okuden-labo / style.css
Last active August 29, 2015 14:17
Bootstrap Containerのサイズをカスタムする方法[改訂版]
/* 通常のcontainerが750px-970px-1170pxなのでsmallの間にmiddeleを追加 */
@media (min-width: 768px) {
.container-small {
width: 300px;
}
.container-middle {
width: 500px;
}
}
@okuden-labo
okuden-labo / copy.html
Created March 19, 2015 03:24
JQueryでコピーライトの年号を自動更新
/* javascriptのコード */
function copyright(){
myDate = new Date();
myYear = "Copyright © "+myDate.getFullYear()+" Company Name Allrights Reserved.";
document.write(myYear);
}
/* htmlのコード */
<script type="text/javascript">copyright();</script>
@okuden-labo
okuden-labo / click.js
Last active August 29, 2015 14:17
jQueryで右クリックを無効にする方法
/*コンテキストメニューが非表示に*/
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
@okuden-labo
okuden-labo / smmoth.js
Last active August 29, 2015 14:17
jQueryでスムーズリンク(1)
/* ページ内リンクをスムーズに移動させます。 */
$(document).ready(function() {
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
@okuden-labo
okuden-labo / replace.js
Created March 19, 2015 03:32
jQueryで置換
/* 要素の中身を書き換え */
$(document).ready(function() {
$('#my-id').replaceWith('<div>置換後の文字列</div>');
});
@okuden-labo
okuden-labo / clock.js
Created March 19, 2015 03:34
jQueryでDIVをクリック可能に
/* クリック要素を大きくできます */
$(document).ready(function() {
$("div").click(function(){
//aタグから遷移先を自動取得します。
window.location=$(this).find("a").attr("href");
return false;
});
});
@okuden-labo
okuden-labo / center.js
Created March 19, 2015 03:35
jQueryで画面の中心
/* 画面の中心に要素を配置 */
$(document).ready(function() {
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$("#my-id").center();
@okuden-labo
okuden-labo / size.js
Created March 19, 2015 03:37
jQueryで要素の数を数える
$(document).ready(function() {
$("p").size();
});
@okuden-labo
okuden-labo / alert.js
Created March 19, 2015 03:46
jQueryでアラートを表示する
//テキストボックスからフォーカスが外れた時
//ボタンを押したとき(id指定)
//テキストをクリックしたとき(タグとクラス指定)
jQuery(function ($) {
// テキストボックスからフォーカスが外れた時
$("#form1 [name=text1]").blur(function() {
alert($('#form1 [name=text1]').val());
});
@okuden-labo
okuden-labo / pagetop.html
Created March 19, 2015 07:05
jQueryでスムーズリンク(2)
/* ページトップへスクロールする */
/* css */
.toTop {
margin-top: 400px;
display: inline-block;
background: #0bd;
padding: 15px;
color: #fff;
cursor: pointer;
}