简体   繁体   中英

FadeIn and fadeOut effect on onclick function

Is it possible fadeIn , fadeOut or other effect on onclick function?

EG When click

<a href="#" onclick="document.getElementById('test').style.backgroundImage='url(img/test.jpg)'" ><span class="left">Test</span>></a>

change background within fade effect?

Try to add this style:

<style>
#test {

transition: background .1s linear;
-webkit-transition: background .1s linear;
-moz-transition: background .1s linear;
-o-transition: background .1s linear;

}
</style>

<a href="#" onclick="document.getElementById('test').style.backgroundImage='url(img/test.jpg)'" ><span class="left">Test</span>></a>
<a href="javascript:changeBackground('img/test.jpg')"><span class="left">Test</span>></a>
<div id="test" style="display: none;"></div>
<script>
    function changeBackground(src) {
        var img = new Image();
        img.src = src;
        img.onload = function () {
            $('#test').fadeIn();
        }
    }
</script>

You can do it with jQuery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM