2017年6月29日 星期四

input數量+ -

HTML
<input type='button' value='-' class='qtyminus' field='quantity' />
    <input type='text' name='quantity' value='0' class='qty' />
    <input type='button' value='+' class='qtyplus' field='quantity' />

    <input type='button' value='-' class='qtyminus' field='quantity2' />
    <input type='text' name='quantity2' value='0' class='qty' />
    <input type='button' value='+' class='qtyplus' field='quantity2' />





JS

//用來做訓練人員數量加減
jQuery(document).ready(function(){
    // This button will increment the value
    $('.qtyplus').click(function(e){
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        fieldName = $(this).attr('field');
        // Get its current value
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        // If is not undefined
        if (!isNaN(currentVal)) {
            // Increment
            $('input[name='+fieldName+']').val(currentVal + 1);
        } else {
            // Otherwise put a 0 there
            $('input[name='+fieldName+']').val(0);
        }
    });
    // This button will decrement the value till 0
    $(".qtyminus").click(function(e) {
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        fieldName = $(this).attr('field');
        // Get its current value
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        // If it isn't undefined or its greater than 0
        if (!isNaN(currentVal) && currentVal > 0) {
            // Decrement one
            $('input[name='+fieldName+']').val(currentVal - 1);
        } else {
            // Otherwise put a 0 there
            $('input[name='+fieldName+']').val(0);
        }
    });
});


CSS
.qty{
    -webkit-appearance: none;
    border-radius: 0;
    line-height: 2.5;
    width: 36px;
    height: 25px;
    border-left: none;
    border-right: none;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    vertical-align: middle;
    text-align: center;
    background-color: #fff;
    margin: 0;
    margin-left: -3px;
    margin-right: -3px;
}
.qtyminus, .qtyplus {
    -webkit-appearance: none;
    border-radius: 0;
    display: inline-block;
    height: 25px;
    width: 20px;
    vertical-align: middle;
    cursor: pointer;
    box-shadow: none;
    border: solid 1px #ccc;
    padding: 0;
    font-size: 20px;
    background: #EEEEEE;
}

2017年3月1日 星期三

Sticky sidebar 的作法

<main>
<div id="content">文字</div>
<aside id="aside">選單</div>
<main>


#content
#aside
可以更名

參考網站
http://spoiledmilk.com/blog/sticky-sidebar/

另一種做法
http://abgne.tw/jquery/jquery-plugins/sticky-sidebar.html

2017年2月2日 星期四

Bootstrap dropdown menu don't work in IE8, 下拉選單在IE8出不來

解決方法:
加上filter:none !important;

.navbar-inverse .nav li.dropdown.open > .dropdown-toggle,
.navbar-inverse .nav li.dropdown.active > .dropdown-toggle,
.navbar-inverse .nav li.dropdown.open.active > .dropdown-toggle,
.nav,
.navbar,
.navbar-inverse .navbar-inner {
filter:none!important;
background-image: none;
}

參考網址:https://github.com/twbs/bootstrap/issues/6548

2016年12月20日 星期二

h1 margin-top 會影響到父層DIV 產生多餘的 margin-top

h1 margin-top 會影響到父層DIV 產生多餘的 margin-top

HTML
<div class="parent"> 
<h1>HI HI HI</h1> 
</div>


css
.parent{margin:0;}
h1{margin: 50px auto; }


解決方案
在父層div加上overflow:auto

.parent{margin:0; overflow:auto;}

參考來源
http://stackoverflow.com/questions/20689575/css-margin-top-of-h1-affects-parents-margin

2016年12月9日 星期五

owlcarousel 100%高的用法

1. 先去GITHUB 下載 owlcarousel 2.0新版
https://github.com/OwlCarousel2/OwlCarousel2

2. 把CSS放到html裡面
CSS 放到<head>裡面

<link rel="stylesheet" href="dist/owlcarousel/owl.carousel.min.css">

<link rel="stylesheet" href="dist/owlcarousel/owl.theme.default.min.css">


3. JS 放到<body>最下面,記得要先引用jquery

<!-- jQuery -->
<script src="//code.jquery.com/jquery.js"></script>

<!--貓頭鷹跑馬燈的JS-->
<script src="dist/owlcarousel/owl.carousel.min.js"></script>
<!--啟用貓頭鷹-->
<script>
$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
nav:true,
items:1
})
</script>
4. html 我用背景的跑馬燈
<div class="owl-carousel">
    <div class="item" style="background-image: url(img/b1.jpg);"><h4>1</h4></div>
    <div class="item" style="background-image: url(img/b2.jpg);"><h4>2</h4></div>
</div>
5. 100高的設定 100% height CSS 設定

html,body{height: 100%;}
body{min-height:100%;}
.owl-carousel{height: 100%;}
.owl-carousel .owl-stage-outer{height: 100%;}
.owl-stage{height: 100%;}
.owl-item {height: 100%;}
.owl-item .item{height: 100%; background-size: cover;background-position: center center;}

2016年11月29日 星期二

圖片置中的好方法,Image Vertical Align

外層DIV 高度與行高一致
裡面的IMG vertical-align:middle

.proudImg{margin:10px;overflow: hidden;height: 200px;line-height:200px;}
.proudImg img{vertical-align:middle;}

2016年11月17日 星期四

RWD

媒體查詢寫法

最大的畫面只到767 手機專用
@media only screen and (max-width: 767px){
}

最大的畫面只到991 平板專用
@media only screen and (max-width: 991px){
}
畫面在1200~992
@media(min-width: 768px) and (max-width: 1200px){
}