Published 2020. 8. 3. 20:42
728x90
반응형

show | hide

<input type="button" value="show" id="btn-show">
<input type="button" value="hide" id="btn-hide">
<input type="button" value="toggle" id="btn-toggle">
<img src="images/river1.PNG" id="img-river" style="display: none;">

<script>
$(function(){
    $("#btn-show").click(function() {
        $("#img-river").show(5000);  
    });
    $("#btn-hide").click(function() {
        $("#img-river").hide(5000);
    });
    $("#btn-toggle").click(function() {
        $("#img-river").toggle(1000,function() {  
            //작업 완료시 호출 메소드
            alert("toggle완료");
        });
    });
});
</script>

 

 

fadeIn | fadeOut | fadeTo

<input type="button" value="fadeIn" id="btn-fadeIn">
<input type="button" value="fadeOut" id="btn-fadeOut">
<hr>
<img src="images/flower5.PNG" id="img-flower" >
<hr>
<div class="img-wrap">
    <img src="images/flower1.PNG" id="img-flower2">
</div>
<style>
.img-wrap{
    width: 500px;
    height: 300px;
    overflow: hidden;
}
.img-wrap img {
    width: 100%;
}
#img-flower2{
    opacity: .7;
    transition-duration: .3s;
}
#img-flower2:hover {
    cursor: pointer;
}
</style>
<script>
    $(function() {
        $("#img-flower2").hover(function() {
            $(this).fadeTo(100,1)
                    .css("transform", "scale(1.1, 1.1)");
        }, function() {
            $(this).fadeTo(100,.7)
                    .css("transform", "scale(1, 1)");
        });
    });

    $(function() {
        $("#btn-fadeIn").click(function() {
            $("#img-flower").fadeIn(1000);
        });
        $("#btn-fadeOut").click(function() {
            $("#img-flower").fadeOut(1000);
        });
    });
</script>

 

 

animate

css animation효과생성. callback함수

<input type="button" value="실행" id="btn-animate">
<hr>
<div id="animate-test"></div>
<style>
#animate-test{
    width: 200px;
    height: 200px;
    background-color: orangered;
    border: 1px solid black;
}
</style>
<script>
$(function() {
    $("#btn-animate").click(function(){
        //animate(style-obj, duration, easing, callback-function)
        let style = {
            width: "500px",
            height: "500px",
            "border": "10px",
            "background-color": "aqua"  //-이 있으면 ""안에 작성하면 됨
        };
        $("#animate-test").animate(style, 2000, function() {
            alert("애니메이션 처리 완료");
        });
    });
});
</script>
<div class="img-container">
    <img src="images/tour1.jpg" style="width:150px;" id="img-tour">
</div>
<style>
.img-container{
    width: 155px;
    height: 105px;
    margin: 0 auto;
    overflow: hidden;
    position: relative;
    border: 1px solid black;
    padding-top: 5px;
    padding-left: 5px;
}
.img-container img{
    position: relative;
    width: 150px;
    height: 100px;
}
</style>
<script>
$(function() {
    $("#img-tour").click(function() {
        let style = {
            left: "-155px"
        };
        $(this).animate(style, 500, function() {
            $(this).css("left", "155px")
                    .animate({left:"0px"},500);
        });
    });
});
</script>
반응형

'프로그래밍 > jQuery' 카테고리의 다른 글

[jQuery] 제이쿼리 엔터키 이벤트  (0) 2022.08.25
jQuery 선택자에 변수 넣기  (0) 2021.11.03
07.31(dom-element)  (0) 2020.07.31
07.30(each, is)  (0) 2020.07.30
07.29(이벤트)  (0) 2020.07.29
복사했습니다!