简体   繁体   English

我如何让它淡出名字

[英]how do i get it to fade to the next name

 var peopleArray = [ {name: 'Abby Sepple', weirdThing: 'Abbey Road and pterodactyl hiccups' }, {name: 'Alayna Buysse', weirdThing: 'Chucky cheese suit and heard that' }, {name: 'Amy Venturino', weirdThing: 'No social media and 2 uvulas' }, {name: 'Barbara King', weirdThing: 'Semi conductor expert and hates touching raw meat' }, {name: 'Benjimin Lauderbaugh', weirdThing: 'minecraft and sleep walking' }, {name: 'Charlie Garnaas', weirdThing: 'Morning ice-cream snacking and hates lines' }, {name: 'Colin James Wymore', weirdThing: 'LOVEs conspiracy theories' }, {name: 'Droo Hastings', weirdThing: 'Touring musician who craved normalcy' }, {name: 'Amal Ali', weirdThing: 'Bust out dancing' }, {name: 'Jim Vang', weirdThing: 'Puts stuff away and lab practical joker' }, {name: 'Jorge Blue', weirdThing: 'Curious person and had a bit of tree branch in bicep for too long' }, {name: 'Kara Bayse', weirdThing: 'Collects all the bags and will never eat white castle' }, {name: 'Matt Larson', weirdThing: 'Experimental everything and collecting things for toy alter' }, {name: 'Neota Moe', weirdThing: 'Loves watching surgeries, even her own and can talk about gross stuff over dinner' }, {name: 'Ryan Beadie', weirdThing: 'Hockey hair mullet perm and seven of his favorite shirts' }, {name: 'Sean Felling', weirdThing: 'Smiles when he is nervous and walks on the outside of his feet' }, {name: 'Tiffany Love', weirdThing: 'Singing even when she does not realize it and Sunday morning breakfasts' }, {name: 'Tessa M Ganser', weirdThing: 'Whale drone videos and big family' }, {name: 'Zeinab Hassan', weirdThing: 'Sweet and savory and Nutella egg breakfasts' } ]; $(onReady); var nameIndex = 0; function onReady() { console.log('inside onReady'); $('#nameDisplay').text('Name'); $('#weirdDisplay').text('Weird'); $('#nameChanger').on('click', nextName); $('#nameBack').on('click', prevName); }//the end of onReady function function nextName() { console.log('inside nextName'); if (nameIndex == peopleArray.length) { console.log('I AM WHERE I NEED TO BE'); nameIndex = 0; } else if (nameIndex == -1) { nameIndex = peopleArray.length - 1; } $('#nameDisplay').text(peopleArray[nameIndex].name); $('#weirdDisplay').text(peopleArray[nameIndex].weirdThing); $('#current').text(nameIndex + 1 + '/19'); nameIndex++; } function prevName() { console.log('inside prevName'); // $('.nameDisplay').attr('value', peopleArray[nameIndex].name); if (nameIndex == peopleArray.length) { console.log('I AM WHERE I NEED TO BE'); nameIndex = 0; } else if (nameIndex == -1) { nameIndex = 19; } nameIndex = nameIndex -1; $('#current').text(nameIndex + '/19'); $('#nameDisplay').text(peopleArray[nameIndex].name); $('#weirdDisplay').text(peopleArray[nameIndex].weirdThing); if (nameIndex === 0) { console.log('I am where i need to be'); nameIndex = 19; // console.log(nameIndex); } if (nameIndex === 0) { console.log('this'); $('#current').text(1 + '/19'); } console.log(nameIndex); } 
 .display { display: inline-block; margin:0; padding:0; } #nameDisplay { font-size: 1.5em; } #weirdDisplay { font-size: 1em; } .button { display: block; font-size: 1em; margin-top: 1em; } 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Weekend Challenge 1</title> <link rel="stylesheet" href="style.css" /> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g=" crossorigin="anonymous"></script> <script type="text/javascript" src="data.js"></script> <script type="text/javascript" src="client.js"></script> </head> <body> <div class="container"> <p class = 'display' id = 'nameDisplay'></p> <p class="display">: </p> <p class = 'display' id = 'weirdDisplay'></p> <p id='current'>something</p> <button type="button" name="button" class ='button' id = 'nameChanger'>Next</button> <button type="button" name="button" class ='button' id = 'nameBack'>Prev</button> </div> </body> </html> 

How do i get this to fade to the next name, I already tried .fadeIn(), but that does not work, Is it fadeToggle or something like that? 我已经尝试过.fadeIn(),如何使它淡化为姓氏,但这不起作用,它是fadeToggle还是类似的东西? I have no idea how to fix this. 我不知道该如何解决。 Also if you see any other bugs please let me know 另外,如果您发现其他错误,请告诉我

fadeIn and fadeOut won't work because you're using slim version of jquery, which doesn't have that functions. fadeInfadeOut将不起作用,因为您使用的是没有该功能的超薄版本的jquery。 You can put 你可以放

<script
    src="https://code.jquery.com/jquery-3.2.1.min.js"
    integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
    crossorigin="anonymous"></script>

instead of 代替

<script
    src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
    integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
    crossorigin="anonymous"></script>

to get full jquery. 获得完整的jQuery。

After that you can use fadeIn and fadeOut like this: 之后,您可以像这样使用fadeIn和fadeOut:

$('#nameDisplay').fadeOut(function(){
    $(this).text(peopleArray[nameIndex].name).fadeIn();
});

In this example - #nameDisplay fades out, then text inside is replaced, and after that #nameDisplay fades back in. 在此示例中- #nameDisplay淡出,然后替换其中的文本,然后#nameDisplay淡出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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