简体   繁体   中英

Wordpress Plugin with Javascript

I am working on a wordpress plugin which allows a user to enter a image url and konami code . When the konami code is entered an image pops up, but I can't get it to animate, I am somewhat unfamiliar with jQuery and Javascript, and I am just starting to learn it... Any help would be fantastic!

<script type="text/javascript" charset="utf-8">
if ( window.addEventListener ) {
  var kkeys = [], konami = "{$this->opts['wpk_code']['current']}";
  window.addEventListener("keydown", function(e){
    kkeys.push( e.keyCode );
    if ( kkeys.toString().indexOf( konami ) >= 0 ){
     var elms=document.getElementById("konami").style;
     elms.display=(elms.display=="block")?"none":"block";
}
  }, true);
}
</script>

尝试一下jQuery animate()上的一些示例-它们似乎可以满足您的要求。

Try this:

$('#inputField').keyup(function () {
            if ($(this).val().length > 0) {
                $('#konami').animate({
                    opacity: 1,
                    left: '50'
                }, 100); 
            }
            else {
                $('#konami').animate({
                    opacity: 0,
                    left: '0'
                }, 100); 
            }
        });

HTML:

<input type="text" id="inputField" />
<img src="..." id="konami" style="position:relative;" />

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